我在我的项目中使用carbonkit。由于选项卡仅将文本/图像作为视图,因此我将文本渲染为图像并将其放在选项卡上。
- (UIImage*) generateImageWithText:(UIImage*)img text:(NSString*)text
{
UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
UIImageView *imgView = [[UIImageView alloc]initWithImage:img];
imgView.backgroundColor = [UIColor clearColor];
imgView.frame = CGRectMake(15, 15, view.bounds.size.width-30, view.bounds.size.height-50);
imgView.contentMode = UIViewContentModeScaleAspectFit;
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, imgView.frame.size.height + 20, view.bounds.size.width, 30)];
lbl.backgroundColor = [UIColor clearColor];
lbl.textAlignment = NSTextAlignmentCenter;
lbl.textColor = [UIColor whiteColor];
lbl.font = [UIFont systemFontOfSize:12];
lbl.text = text;
lbl.lineBreakMode = NSLineBreakByWordWrapping;
lbl.numberOfLines = 2;
[view addSubview:imgView];
[view addSubview:lbl];
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *imageWithText = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageWithText;
}
答案 0 :(得分:0)
首先,您需要从视图中删除文本和图像,然后创建新图像和标签。