前提:app需要适配国际化
占位图上为:上传图片
难点:占位图针对不同国家需要显示不同语言的“上传图片”
用draw解决
代码如下:
+ (UIImage *)drawUploadCoverImageWithSize:(CGSize)size{
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
float textHeight = size.height/3;
// 画图
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, rect);//白色背景
NSString *string = @"上传封面";
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:string];
[attrStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold"size:30.0f] range:NSMakeRange(0, string.length)];
[attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, string.length)];
[attrStr drawInRect:CGRectMake(0, textHeight, size.width, textHeight)];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc]init];
paragraph.alignment = NSTextAlignmentCenter;
[attrStr addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, string.length)];
CGImageRef imgRef = CGBitmapContextCreateImage(context);
UIImage *image = [UIImage imageWithCGImage:imgRef];
CGImageRelease(imgRef);
CGContextRelease(context);
return image;
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。