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];
}
相关推荐
人月神话Lee2 小时前
【图像处理】亮度与对比度——图像的线性变换
ios·ai编程·图像识别
bryceZh3 小时前
iOS26适配-UISplitViewController配置分栏和分屏
ios·ui kit
songgeb3 小时前
NumberFormatter 货币格式化属性详解
ios·swift
最后一支迷迭香6 小时前
苹果的MacOS系统适合做Java开发吗
java·开发语言·macos
AirDroid_cn6 小时前
macOS Sequoia协同编辑:Pages文档冲突自动合并全攻略
macos
irpywp6 小时前
平台禁下载、格式不兼容、剪辑太麻烦,Media Downloader:mac 原生媒体下载工具,一站式解决视频下载、转码、裁剪、管理难题
macos·开源·github·音视频·媒体
for_ever_love__7 小时前
UI学习:数据驱动ce l l
学习·ui·ios·objective-c
KillerNoBlood7 小时前
2026移动端跨平台开发面经总结
android·算法·flutter·ios·移动开发·鸿蒙·kmp
城管不管8 小时前
Maven Helper
java·macos·intellij-idea
人月神话-Lee8 小时前
【图像处理】颜色科学与灰度化——人眼看到的和数字记录的不一样
图像处理·人工智能·计算机视觉·ios·swift