我创建了一个称为CircleView的UIView
,它绘制了一个圆。只需单击一下按钮即可添加该文件,并在另一个视图canvasView中将UITapGestureRecognizer
作为子视图定位。
这是圆的代码,它的工作原理是:
@IBAction func tapCircle(_ sender: UITapGestureRecognizer) {
let tapPoint2 = sender.location(in: canvasView)
let shapeCircle = CircleView(origin: tapPoint2)
canvasView.addSubview(shapeCircle)
shapeCircle.tag = 300
}
@IBAction func circleDraw(_ sender: UIButton) {
canvasView.isUserInteractionEnabled = true
tapCircle.isEnabled = true
tapRect.isEnabled = false
tapGRQ.isEnabled = false
canvasView.setNeedsDisplay()
}
一切都很好,但我想知道是否有可能通过单击按钮来更改此形状的颜色。非常感谢。
答案 0 :(得分:0)
为形状数组创建全局变量
User-agent: Mediapartners-Google
Disallow:
User-agent: *
Disallow: /Ajax/
Disallow: /ajax/
Disallow: /Uploads/
Disallow: /uploads/
Disallow: /cms/
Disallow: /cooks/
Disallow: /login/
Disallow: /m/cooks/
Disallow: /m/my-stuff/
Disallow: /*/email-a-friend.aspx
Disallow: /*/print-friendly.aspx
Disallow: /search/ # search controller path
Disallow: /*/searchresults.aspx
Disallow: /*/galleryview.aspx
Sitemap: http://allrecipes.co.uk/sitemap.xml.gz
然后在创建新var circleShapes = [UIView]()
var squareShapes = [UIView]()
...
后将其添加到特定数组
UIView
现在只需为特定数组内的每个视图更改let shapeCircle = CircleView(origin: tapPoint2)
canvasView.addSubview(shapeCircle)
circleShapes.append(shapeCircle)
...
backgroundColor
或者如果您的circleShapes.forEach { $0.backgroundColor = /* UIColor */ }
...
仅包含 shapes 子视图,则每个 shape 都有其自己的canvasView
子类,并且您想在同一颜色下进行更改时间,您可以根据 shape
UIView
backgroundColor