根据数字,转成对应的图片文章来源地址https://www.toymoban.com/news/detail-627038.html
- (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];
}
文章来源:https://www.toymoban.com/news/detail-627038.html
到了这里,关于iOS数字转为图片的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!