如何解决如何在Swift 5 Playground中绘制文本,形状,线条
我正试图在操场上以5速画一张井字棋。
我在左上方的方框中画圆时遇到问题。 addArc函数绘制半径加上圆(我不确定为什么吗?)。我宁愿使用具有适当字体属性的text(“ O”,“ X”)为文本着色和调整大小,但我也想知道如何绘制没有半径的圆。
这在操场上有可能吗?有人可以帮忙吗?
示例代码:
import UIKit
import PlaygroundSupport
public class SimpleLine: UIView {
public init() {
super.init( frame: CGRect( x: 0,y: 0,width: 320,height: 480 ) )
backgroundColor = .darkGray
}
public required init?( coder aDecoder: NSCoder ) {
fatalError("init(coder:) has not been implemented")
}
public override func draw( _ rect: CGRect ) {
guard let context = UIGraphicsGetCurrentContext() else {return}
context.setlinewidth( 4.0 )
context.setstrokeColor( UIColor.red.cgColor )
// draw right perpendicular line
context.move( to: CGPoint( x: 110,y: 100 ) )
context.addLine( to: CGPoint( x: 110,y: 355 ) )
// draw left perpendicular line
context.move( to: CGPoint( x: 210,y: 100 ) )
context.addLine( to: CGPoint( x: 210,y: 355 ) )
// draw the first horizontal line
context.move( to: CGPoint( x: 20,y: 180 ) )
context.addLine( to: CGPoint( x: 300,y: 180 ) )
// draw the second horizontal line
context.move( to: CGPoint( x: 20,y: 270 ) )
context.addLine( to: CGPoint( x: 300,y: 270 ) )
// draw the tictac board
context.strokePath()
context.setlinewidth( 2.0 )
context.setstrokeColor( UIColor.white.cgColor )
// draw first part of the X
context.move( to: CGPoint( x: 130,y: 199 ) )
context.addLine( to: CGPoint( x: 190,y: 250 ) )
// draw second part of the X
context.move( to: CGPoint( x: 190,y: 199 ) )
context.addLine( to: CGPoint( x: 130,y: 250 ) )
// draw circle
context.move( to: CGPoint( x: 62,y: 138 ) )
context.addArc( center: CGPoint( x: 62,y: 138 ),radius: 26.00,startAngle: 0,endAngle: 90,clockwise: false )
context.strokePath()
}
}
PlaygroundPage.current.liveView = SimpleLine()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。