gpt4 book ai didi

ios - 我的自定义形状后面的颜色已填充,我想将其设为白色

转载 作者:行者123 更新时间:2023-12-01 15:46:46 26 4
gpt4 key购买 nike

本质上图片显示了它,但我想使橙色形状后面的灰色背景透明和/或白色(或坦率地说是任何颜色)。我只是想知道在哪里可以更改形状背景的颜色以及它的语法是什么。 IMAGE

class DemoView: UIView {

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/

var path: UIBezierPath!

override init(frame: CGRect) {
super.init(frame: frame)

self.backgroundColor = UIColor.darkGray

}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

func createRectangle() {
path = UIBezierPath()

path.move(to: CGPoint(x:0.0, y: 0.0))

path.addLine(to: CGPoint(x: 0.0, y: 300.0))

//path.addLine(to: CGPoint(x: self.frame.size.width, y: self.frame.size.height))


//self.frame.size.height
path.addCurve(to:CGPoint(x: self.frame.size.width, y: 300.0), controlPoint1: CGPoint(x: self.frame.size.width/2, y: 400), controlPoint2: CGPoint(x: self.frame.size.width/2, y: 400))

path.addLine(to: CGPoint(x: self.frame.size.width, y: 0.0))

path.close()
}

override func draw(_ rect: CGRect) {
self.createRectangle()

UIColor.orange.setFill()
path.fill()

UIColor.purple.setStroke()
path.stroke()


}
}

在下面的 View Controller 中

let height: CGFloat = 400.0

let demoView = DemoView(frame: CGRect(x: 0,
y: self.view.frame.size.height/2 - height/2,
width: self.view.frame.size.width,
height: height))

self.view.addSubview(demoView)

最佳答案

您可以通过更改演示 View 背景颜色来更改它

let demoView = DemoView(frame: CGRect(x: 0,
y: self.view.frame.size.height/2 - height/2,
width: self.view.frame.size.width,
height: height))
demoView.backgroundColor = .green
self.view.addSubview(demoView)

你也可以在你的 DemoView init 方法中改变它

  class DemoView: UIView {

var path: UIBezierPath!

override init(frame: CGRect) {
super.init(frame: frame)

// self.backgroundColor = UIColor.darkGray
self.backgroundColor = // Any color you want or clear color
}

enter image description here

关于ios - 我的自定义形状后面的颜色已填充,我想将其设为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61491294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com