iOS数字转为图片


根据数字,转成对应的图片

objectivec 复制代码
- (void)viewDidLoad {
    [super viewDidLoad];

    [self testNum2String:10086];
}

/// 根据数字,显示对应的图片 数字用特定的图片显示
- (void)testNum2String:(NSInteger)num {
    
    UIView *numContentView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 0, 20)];
    numContentView.backgroundColor = UIColor.redColor;
    
    NSString *str = [NSString stringWithFormat:@"%zd", num];
    NSInteger length = str.length;
    for (int i = 0; i < length; i++) {
        // 取到每一位数字 这一行是关键代码
        char ch = [str characterAtIndex:i];
        
        NSLog(@"word is %c", ch);
        NSString *imgName = [NSString stringWithFormat:@"icon_num_%c", ch];
        // 根据数字,取对应的图片
        UIImage *img = [UIImage imageNamed:imgName];
        UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
        imgView.frame = CGRectMake(numContentView.frame.size.width, 0, 10, 20);
        [numContentView addSubview:imgView];
        numContentView.frame = CGRectMake(100, 100, CGRectGetMaxX(imgView.frame), 20);
    }
    
    [self.view addSubview:numContentView];
}
相关推荐
初遇你时动了情6 小时前
uniapp/flutter中实现苹果IOS 26 毛玻璃效果、跟随滑动放大动画
flutter·ios·uni-app
2501_916007478 小时前
Fastlane 结合 开心上架(Appuploader)命令行实现跨平台上传发布 iOS App 的完整方案
android·ios·小程序·https·uni-app·iphone·webview
CV大师杨某9 小时前
如何在uni-app中禁用iOS橡皮筋效果?
ios·uni-app
2501_9159184112 小时前
iOS 上架应用市场全流程指南,App Store 审核机制、证书管理与跨平台免 Mac 上传发布方案(含开心上架实战)
android·macos·ios·小程序·uni-app·cocoa·iphone
C_philadd13 小时前
Xcode26升级以后重要
ios
2501_9159090614 小时前
HTTPS 错误排查实战,从握手到应用层的工程化流程
网络协议·http·ios·小程序·https·uni-app·iphone
darkb1rd15 小时前
MacCalendar:专为 Mac 用户打造的高效日历工具
macos
美狐美颜sdk1 天前
跨平台直播美颜sdk集成攻略:Android、iOS与Web的统一方案
android·前端·ios
神秘剑客_CN1 天前
MacOS学习笔记
笔记·学习·macos
2501_915106321 天前
“HTTPS Everywhere” 的工程化实践,从全面加密到排查与真机取证
网络协议·http·ios·小程序·https·uni-app·iphone