使用tintColor改变图片的颜色

来源:互联网 发布:深圳市软件产业基地5栋 编辑:程序博客网 时间:2024/05/18 02:41

  _myImage =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];    _myImage =[UIImage imageNamed:@"shinobihead.png"]; // Set the rendering mode to respect tint color    _myImage.image =[self.myImage.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];    [self.view addSubview:_myImage];  // Generate a random color    CGFloat hue =(arc4random() % 256 /256.0);    CGFloat saturation =(arc4random() % 128 /256.0)+0.5;    CGFloat brightness =(arc4random() % 128 /256.0)+0.5;    UIColor* color =[UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];    self.myImage.tintColor =color;

                                             
0 0
原创粉丝点击