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];
}
相关推荐
2501_915918413 小时前
iOS 26 App 性能测试|性能评测|iOS 26 性能对比:实战策略
android·macos·ios·小程序·uni-app·cocoa·iphone
wulitoud6 小时前
[自荐]一款mac电脑历史剪切板工具,类似著名的Paste
macos
Digitally9 小时前
如何通过 5 种有效方法同步 Android 和 Mac
android·macos
namehu13 小时前
React Native 应用性能分析与优化不完全指南
android·react native·ios
游戏开发爱好者819 小时前
BShare HTTPS 集成与排查实战,从 SDK 接入到 iOS 真机调试(bshare https、签名、回调、抓包)
android·ios·小程序·https·uni-app·iphone·webview
2501_9160088919 小时前
iOS 26 系统流畅度实战指南|流畅体验检测|滑动顺畅对比
android·macos·ios·小程序·uni-app·cocoa·iphone
Digitally20 小时前
如何处理旧 iPhone:安全地回收或重新利用
安全·ios·iphone
岁月向前20 小时前
iOS蓝牙常见问题
ios
一大树20 小时前
H5在不同操作系统与浏览器中的兼容性挑战及全面解决方案
前端·ios