iOS 修改同一套图的颜色

来源:互联网 发布:linux永久挂载硬盘 编辑:程序博客网 时间:2024/04/29 07:52

第一种:很简单,但是只能更改图片中线条的颜色,不能更改填充的颜色 
步骤:1 在图片管理器中选中图片 
2:点击图片,选中如图格式 
3:在代码中更改uiimageView颜色:

      imgV.tintColor = [UIColor blackColor];
  • 1
  • 1

第二种:可以将里面的内容的颜色为想要的颜色 
创建一个类别 
注意红线选中地方

2 在创建的类别写如下代码
@interface UIImage (UIImage_Tint)- (UIImage *) imageWithTintColor:(UIColor *)tintColor;- (UIImage *) imageWithGradientTintColor:(UIColor *)tintColor;@end
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3 在.m文件中

 #import "UIImage+UIImage_Tint.h"@implementation UIImage (UIImage_Tint)- (UIImage *) imageWithTintColor:(UIColor *)tintColor{    return [self imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];}- (UIImage *) imageWithGradientTintColor:(UIColor *)tintColor{    return [self imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay];}- (UIImage *) imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode{    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);    [tintColor setFill];    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);    UIRectFill(bounds);    //Draw the tinted image in context    [self drawInRect:bounds blendMode:blendMode alpha:1.0f];    if (blendMode != kCGBlendModeDestinationIn) {        [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];    }    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return tintedImage;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果5s蓝屏开不了机怎么办 红米pro更新开发版发热卡怎么办 5s手机音量增大键失灵怎么办 眼睛看手机久了模糊应怎么办 华为无线自拍杆连opp手机怎么办 苹果手机进水后自动跳电怎么办 魅族手机返回键不好使怎么办 手机壳是玻璃的摔坏了怎么办 魅族手机进水了开不了机怎么办 打发票机屏忘记了密码怎么办 魅族手机升级显示电量不足怎么办 魅蓝手机的图库没了怎么办 魅蓝5s屏幕碎了怎么办 魅族手机中间的home键失灵怎么办 魅族手机突然关机开不了机了怎么办 魅蓝3s卡顿怎么办视频 魅蓝3s手机太卡怎么办 红米4x外放破音怎么办 魅族手机刷机后内存变小了怎么办 手机用久了内存越来越小怎么办魅族 贴了车膜左右后视镜反光怎么办 贴手机膜时酒精没了怎么办 魅蓝e外屏幕碎了怎么办 贴的手机膜边缘翘起来着怎么办 手机后面贴的膜都是胶怎么办 车漆外面一层保护膜被划开了怎么办 美团骑手gps信号弱时怎么办 华为荣耀4x充电插口坏了怎么办 华为畅享5s开不了机怎么办 华为梅特10忘记账号密码怎么办 华为荣耀8充电接口坏了怎么办 华为手机锁屏了自动开屏怎么办 支付宝收货地址写错了怎么办 支付宝领海报地址写错了怎么办 手机总是弹出日历已停止运行怎么办 华为mate8忘了锁屏密码怎么办 红米4a打王者卡怎么办 苹果5s软件更新密码忘记了怎么办 华为荣耀P9进水了没有声音怎么办 华为荣耀7原相机不能拍照怎么办 华为手机触屏密码忘记了怎么办