UITableViewRowAction 自定义 标题颜色 背景色 图片
先说下大体思路,先先创建 label 设置 字体和颜色(也可以 是 imageview ) 。然后利用 UIGraphics 绘制成图片,然后利用
+ (UIColor *)colorWithPatternImage:(UIImage *)image; 这个 方法把图片转换成颜色, 最后设置 UITableViewRowAction 背景色 就完成了
UIImage *(^GetImageWithView)(UIView *) = ^(UIView *view) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
};
UIColor *(^getColorWithLabelText)(NSString *, UIColor *, UIColor *) = ^(NSString *text, UIColor *textColor, UIColor *bgColor) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 80)];
view.backgroundColor = bgColor;
UILabel *actionLb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 150, 80)];
actionLb.font = [UIFont boldSystemFontOfSize:14];
actionLb.text = text;
actionLb.textColor = textColor;
actionLb.textAlignment = NSTextAlignmentLeft;
[view addSubview:actionLb];
return [UIColor colorWithPatternImage:AddressimageWithView(view)];
};
在下面调用就可以了