How to create a black UIImage?

后端 未结 5 1097
无人共我
无人共我 2021-02-08 21:42

I\'ve looked around everywhere, but I can\'t find a way to do this. I need to create a black UIImage of a certain width and height (The width and height change, so I can\'t just

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-08 21:58

    Like this

    let image = UIGraphicsImageRenderer(size: bounds.size).image { _ in
          UIColor.black.setFill()
          UIRectFill(bounds)
    }
    

    As quoted in this WWDC vid

    There's another function that's older; UIGraphicsBeginImageContext. But please, don't use that.

提交回复
热议问题