How can I color a UIImage in Swift?

后端 未结 20 2231
执念已碎
执念已碎 2020-11-29 18:27

I have an image called arrowWhite. I want to colour this image to black.

func attachDropDownArrow() -> NSMutableAttributedString {
    let im         


        
20条回答
  •  渐次进展
    2020-11-29 19:12

    There's a built in method to obtain a UIImage that is automatically rendered in template mode. This uses a view's tintColor to color the image:

    let templateImage = originalImage.imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)
    myImageView.image = templateImage
    myImageView.tintColor = UIColor.orangeColor()
    

提交回复
热议问题