CarbonKit - 刷新/重新加载选项卡视图

时间:2017-05-29 08:16:24

标签: ios objective-c

我在我的项目中使用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;
}

我需要点击按钮重新加载/刷新标签视图(不是标签页控制器)。但是标签重叠(以前的新标签)。我该如何解决这个问题? enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

首先,您需要从视图中删除文本和图像,然后创建新图像和标签。