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];
}
相关推荐
与火星的孩子对话2 小时前
Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
android·unity·ios·c#·ip
九丝城主13 小时前
2025使用VM虚拟机安装配置Macos苹果系统下Flutter开发环境保姆级教程--上篇
服务器·flutter·macos·vmware
芳草萋萋鹦鹉洲哦18 小时前
【vue3+tauri+rust】如何实现下载文件mac+windows
windows·macos·rust
恋猫de小郭1 天前
Flutter Widget Preview 功能已合并到 master,提前在体验毛坯的预览支持
android·flutter·ios
点金石游戏出海1 天前
每周资讯 | Krafton斥资750亿日元收购日本动画公司ADK;《崩坏:星穹铁道》新版本首日登顶iOS畅销榜
游戏·ios·业界资讯·apple·崩坏星穹铁道
旷世奇才李先生1 天前
Swift 安装使用教程
开发语言·ios·swift
90后的晨仔1 天前
Xcode16报错: SDK does not contain 'libarclite' at the path '/Applicati
ios
finger244801 天前
谈一谈iOS线程管理
ios·objective-c
Digitally1 天前
如何将大型视频文件从 iPhone 传输到 PC
ios·iphone
梅名智1 天前
IOS 蓝牙连接
macos·ios·cocoa