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];
}
相关推荐
吴佳浩9 小时前
OpenClaw macOS 完整安装与本地模型配置教程(实战版)
人工智能·macos·agent
开心就好202515 小时前
iOS App 安全加固流程记录,代码、资源与安装包保护
后端·ios
开心就好202516 小时前
iOS App 性能测试工具怎么选?使用克魔助手(Keymob)结合 Instruments 完成
后端·ios
zhongjiahao2 天前
面试常问的 RunLoop,到底在Loop什么?
ios
wvy3 天前
iOS 26手势返回到根页面时TabBar的动效问题
ios
RickeyBoy3 天前
iOS 图片取色完全指南:从像素格式到工程实践
ios
aiopencode3 天前
使用 Ipa Guard 命令行版本将 IPA 混淆接入自动化流程
后端·ios
二流小码农3 天前
鸿蒙开发:路由组件升级,支持页面一键创建
android·ios·harmonyos
vi_h4 天前
在 macOS 上通过 Docker 安装并运行 Ollama(详细可执行教程)
macos·docker·ollama
iceiceiceice4 天前
iOS PDF阅读器段评实现:如何从 PDFSelection 精准还原一个自然段
前端·人工智能·ios