1 override func draw(_ rect: CGRect) {
2
3 // 文字绘制 - 可以做文字水印
4 let str = "打脸啊" as NSString
5
6 let attDict:[String:Any] = [NSFontAttributeName:UIFont.systemFont(ofSize: 16),
7 NSForegroundColorAttributeName:UIColor.red]
8
9 let point = CGPoint(x: 20, y: 20)
10 // str.draw(in: <#T##CGRect#>, withAttributes: <#T##[String : Any]?#>)
11 str.draw(at: point, withAttributes: attDict)
12
13
14 // 图片绘制 - 可以做图片水印
15 let img = UIImage(named: "logo")!
16 // img.draw(at: <#T##CGPoint#>)
17 //img.draw(in: <#T##CGRect#>)
18 // 以平铺方式绘制图片,大小跟图片的真实大小一样
19 img.drawAsPattern(in: <#T##CGRect#>)
20
21 // 而且:iOS7.0之后,UIView具有以下方法,各种控件都可以加到水印上
22 // func drawHierarchy(in rect: CGRect, afterScreenUpdates afterUpdates: Bool) -> Bool
23
24 }