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];
}
相关推荐
子沫20201 小时前
mac下载VMware Fusion
macos·mac·vmware fusion
xwz_new4 小时前
数字芯片验证工具之Mac安装Icarus Verily+ GTKWave+VScode(免费)
macos·ic验证
卵男(章鱼)7 小时前
系统终端命令对比大全(Linux发行/macOS/Windows)
linux·运维·服务器·windows·macos
SNOWPIAOP7 小时前
从MAC电脑复制qwen3.5:4b 的OLLAMA模型到LINUX电脑实践
linux·运维·macos·manifest·ollama·blobs
SameX8 小时前
我做了个专注 App,把连续打卡阈值从 3/7/14 改成 2/5 之后留存明显好了
ios
一直会游泳的小猫9 小时前
Homebrew - macOS 与 Linux 的包管理器
linux·运维·macos·brew·包管理工具
pop_xiaoli9 小时前
【iOS】分类、关联对象
ios·分类·数据挖掘·objective-c·cocoa
lwf0061649 小时前
解决macOS .dmg 文件无法安装问题
macos·策略模式
Mr -老鬼9 小时前
EasyClick iOS版 CLI 与 Trae iOS版智能体
ios·自动化·ai编程·tare·ec·easyclick·易点云测
青柠小苍兰9 小时前
Mac(M4 Pro)安装 Parallels Desktop 20 + Windows 11 ARM 完整教程
arm开发·macos·虚拟机·parallels