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];
}
相关推荐
小妖66644 分钟前
MAC在home下新建文件夹报错“mkdir: test: Operation not supported”
macos
m0_641031054 小时前
在选择iOS代签服务前,你必须了解的三大安全风险
ios
北冥有鱼被烹5 小时前
【问题解决】mac笔记本遇到鼠标无法点击键盘可响应处理办法?(Command+Option+P+R)
macos
开开心心loky5 小时前
[iOS] push 和 present Controller 的区别
ui·ios·objective-c·cocoa
Winter_Sun灬9 小时前
Mac开发第一步 - 安装Xcode
ide·macos·xcode
白玉cfc11 小时前
【iOS】push,pop和present,dismiss
macos·ios·cocoa
低调小一12 小时前
iOS 开发入门指南-HelloWorld
ios
2501_9159184112 小时前
iOS 开发全流程实战 基于 uni-app 的 iOS 应用开发、打包、测试与上架流程详解
android·ios·小程序·https·uni-app·iphone·webview
李游Leo14 小时前
LaTeX TeX Live 安装与 CTAN 国内镜像配置(Windows / macOS / Linux 全流程)
linux·windows·macos
华溢澄18 小时前
macOS下基于Qt/C++的OpenGL开发环境的搭建
c++·qt·macos·opengl