ios: change the colors of a UIImage

前端 未结 8 858
旧时难觅i
旧时难觅i 2020-11-27 12:50

I am working on an Iphone application.

I have png pictures that represents symbols. symbols are all black with a transparent background.

Is there a way I can

8条回答
  •  半阙折子戏
    2020-11-27 13:11

    The easiest and shortest:

    Way to do that in case when you dealing with UIImageView:

    Obj-C:

    theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    [theImageView setTintColor:[UIColor redColor]];
    

    Swift:

    let theImageView = UIImageView(image: UIImage(named:"foo")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate))
    theImageView.tintColor = UIColor.redColor()
    

提交回复
热议问题