使用UIBezierPath在Swift中绘制椭圆
发布时间:2020-12-14 02:28:29 所属栏目:百科 来源:网络整理
导读:我有一个UIViewController,我想在屏幕上绘制一个椭圆,从CGPoint开始(x:160,y:160),宽度:240,高度:320.我怎么能在 swift中做到这一点? 我非常感谢任何帮助. 我相信这就是你要求的: var ovalPath = UIBezierPath(ovalInRect: CGRectMake(160,160,240,320
我有一个UIViewController,我想在屏幕上绘制一个椭圆,从CGPoint开始(x:160,y:160),宽度:240,高度:320.我怎么能在
swift中做到这一点?
我非常感谢任何帮助.
我相信这就是你要求的:
var ovalPath = UIBezierPath(ovalInRect: CGRectMake(160,160,240,320)) UIColor.grayColor().setFill() ovalPath.fill() 对于复杂的形状,我建议查看PaintCode.当你在屏幕上绘制形状时,它会为你创建快速的代码(它在过去为我个人节省了很多时间). 编辑: import Foundation import UIKit class CustomOval: UView { override func drawRect(rect: CGRect) { var ovalPath = UIBezierPath(ovalInRect: CGRectMake(0,320)) UIColor.grayColor().setFill() ovalPath.fill() } } 然后 : var exampleView = CustomOval() 然后用约束等定位它. 斯威夫特4 var ovalPath = UIBezierPath(ovalIn: CGRect(x: 160,y: 160,width: 240,height: 320)) UIColor.gray.setFill() ovalPath.fill() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |