Api 接口返回 base64 图片字符串,需要显示在UIImageView 上。
假设 string类型的 base64ImageStr 为 api返回的 base64字符串
将base64字符串进行处理
//去除掉首尾的空白字符和换行字符NSString * img64 = [img stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//进行空字符串的处理img64 = [img64 stringByReplacingOccurrencesOfString:@"\r" withString:@""];//进行换行字符串的处理img64 = [img64 stringByReplacingOccurrencesOfString:@"\n" withString:@""];//进行字符串转data数据NSData * decodedImgData = [[NSData alloc] initWithBase64EncodedString:img64 options:NSDataBase64DecodingIgnoreUnknownCharacters];//把data数据转换成图片内容weakSelf.picCodeImageView.image = [UIImage imageWithData:decodedImgData];
//去除掉首尾的空白字符和换行字符
NSString * img64 = [base64ImageStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//进行空字符串的处理
img64 = [img64 stringByReplacingOccurrencesOfString:@"\r" withString:@""];
//进行换行字符串的处理
img64 = [img64 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//进行字符串转data数据
NSData * decodedImgData = [[NSData alloc] initWithBase64EncodedString:img64 options:NSDataBase64DecodingIgnoreUnknownCharacters];
//把data数据转换成图片内容
weakSelf.picCodeImageView.image = [UIImage imageWithData:decodedImgData];