简体   繁体   中英

UIBezierPath color change custom

I need to change the color of the UIBezierPath, but if I set a custom color, then there is simply no color.

UIColor(red: 255/255.0, green: 249/255.0, blue: 244/255.0, alpha: 1.0)

Tried adding colors via extension, but there is no color either.

UIColor.themeColor.setFill()

extension UIColor {
  class var themeColor: UIColor {
    return UIColor(red: 255/255.0, green: 249/255.0, blue: 244/255.0, alpha: 1.0)
  }
}

Standard colors like.blue, .green, .red - work, but I need to understand how to set my own color through rgb

Here is my code

class MyView: UIView {
    override func draw(_ rect: CGRect) {
        let path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 303.19, height: 495.93))
       
        path.stroke()
 
    }
}



let views = MyView(frame: CGRect(x: 36.62, y: 77.54, width: 303.19, height: 495.93))
        views.backgroundColor = .clear
        views.rotate(radians: -45.84)

        view.addSubview(views)

Use this if you want to change the color in UIBezierPath

path.fillColor = UIColor(red: 255/255.0, green: 249/255.0, blue: 244/255.0, alpha: 1.0).cgColor

path.fillColor = UIColor.red.cgColor

path.fillColor = UIColor(red: 155/255.0, green: 149/255.0, blue: 234/255.0, alpha: 1.0).cgColor

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Works well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM