iOS一个应用有多个颜色主题时,用到图片的地方如何处理

来源:互联网 发布:斐讯路由器 淘宝 编辑:程序博客网 时间:2024/06/07 00:28

一个应用有多个颜色主题时,用到图片的地方如何处理,本文将介绍两种处理方法:

第一种方法:处理UIImage

- (UIImage *)imageWithColor:(UIColor *)color{    UIGraphicsBeginImageContextWithOptions(self.size, NO, 2);    CGContextRef context = UIGraphicsGetCurrentContext();    CGContextTranslateCTM(context, 0, self.size.height);    CGContextScaleCTM(context, 1.0005, -1.0);    CGContextSetBlendMode(context, kCGBlendModeNormal);    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);    CGContextClipToMask(context, rect, self.CGImage);    [color setFill];    CGContextFillRect(context, rect);    UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return newImage;}


第二种方法:使用UIButton,代替UIImageView来显示图片

1.在xib布局中添加的,修改UIButton的type的属性为System,然后调整tintcolor属性即可;

2.纯代码添加视图

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];    btn.frame = CGRectMake(100, 100, width-200, 30);    [btn setImage:image forState:UIControlStateNormal];    [btn setTitle:item.title forState:UIControlStateNormal];    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];<pre name="code" class="objc">    [btn setTintColor:KUnSelectedTitleAttributes];//设置样色
<p class="p2"><span class="s2">    btn.</span><span class="s1">userInteractionEnabled</span><span class="s2"> = </span><span class="s3">NO</span><span class="s2">;//根据需要设置</span></p>




0 0
原创粉丝点击