//如果希望绘制在屏幕上,应该drawRect出发
let str: NSString = "abc"
str.drawAtPoint(CGPoint(x: 0, y: 0), withAttributes: [
//字体颜色
NSForegroundColorAttributeName:UIColor.redColor(),
//背景颜色
NSBackgroundColorAttributeName:UIColor.whiteColor()
])
let image = UIImage(named: "showqrcode.jpeg")
image?.drawInRect(CGRect(x: 20, y: 20, width: 150, height: 150))
//1. 获取当前的绘图环境(绘制到屏幕)
//line/rectangle/arc/ellipse/
//text/image
let cxt = UIGraphicsGetCurrentContext() //CGContextRef
//边框(Stroke),填充(Fill)
//绘图者模式
//设置起点
CGContextMoveToPoint(cxt, 0, 0)
//设置终点
CGContextAddLineToPoint(cxt, 100, 100)
CGContextAddLineToPoint(cxt, 0, 200)
CGContextMoveToPoint(cxt, 150, 150)
CGContextAddLineToPoint(cxt, 200, 200)
CGContextSetLineWidth(cxt, 20)
CGContextSetLineJoin(cxt, .Round)
//1. 颜色设置,改变了绘图环境,cxt
// UIColor.purpleColor().setStroke()
//Red/Green/Blue/Alpha
// CGContextSetStrokeColor(cxt, [1, 0, 0, 1])
CGContextSetStrokeColorWithColor(cxt, UIColor.blueColor().CGColor)
//真正绘制,当前点失效,笔离开
CGContextStrokePath(cxt)
CGContextMoveToPoint(cxt, 150, 0)
CGContextAddLineToPoint(cxt, 150, 150)
CGContextSetLineWidth(cxt, 1)
// CGContextSetLineWidth(cxt, 10)
// CGContextSetLineCap(cxt, .Round)
//虚线:偏移 重复模式 重复数组中元素的个数
CGContextSetLineDash(cxt, 2, [4, 4], 2)
//1.
UIColor.redColor().setStroke()
CGContextStrokePath(cxt)
网友评论