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];
}
相关推荐
瓜子三百克6 小时前
Mac中M系列芯片采用rbenv管理ruby版本
macos·ruby·rbenv
AirDroid_cn6 小时前
手机防沉迷新招:安卓手机如何成为管理iPhone的遥控器?
android·ios·智能手机·iphone·ipad
林大鹏天地7 小时前
iOS borderWidth为0.5边框上下不均匀问题探究和解决
ios
笑道三千7 小时前
react-native在mac的m2芯片下,pod install安装glog的时候报错
macos
GawynKing11 小时前
Neo4j 社区版 Mac 安装教程
macos·neo4j
神奇大叔11 小时前
mac 技巧
macos
iFlyCai12 小时前
Flutter兼容的iOS的最低版本号
macos·objective-c·cocoa
0wioiw013 小时前
Apple基础(Xcode⑤-Flutter-Singbox-AI提示词)
flutter·macos·xcode
喵手1 天前
使用ASIWebPageRequest库编写Objective-C下载器程序
开发语言·macos·objective-c
0wioiw01 天前
Apple基础(Xcode②-Flutter结构解析)
flutter·macos·xcode