根据数字,转成对应的图片
- (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];
}