user7459574
user7459574

Reputation:

add uiColor for cgsize (swift3)

Right now newSize just creates a white box. I would like newSize to be a blue box. How do I add uiColor to newSize?

          let newSize: CGSize = CGSize(width: 900, height: 900)
        UIGraphicsBeginImageContext(newSize)

Upvotes: 1

Views: 99

Answers (1)

Leo Dabus
Leo Dabus

Reputation: 236370

You need to use your color setFill() method to define the color that you would like to fill your image context and just use a UIBezierPath to fill the desired area:

let newSize = CGSize(width: 900, height: 900)
UIGraphicsBeginImageContextWithOptions(newSize, false, 0)
defer { UIGraphicsEndImageContext() } 

UIColor.blue.setFill()
UIBezierPath(rect: CGRect(origin: .zero, size: newSize)).fill()

UIGraphicsGetImageFromCurrentImageContext()

Upvotes: 1

Related Questions