这是swift
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tip)
view.addSubview(codeImageView)
}
lazy var tip:UILabel= {
let tip =UILabel(frame:CGRect(x:0, y:64, width:200, height:200))
tip.text="恭喜"
tip.numberOfLines=0
tip.textColor=UIColor.black
tip.textAlignment= .center
tip.font=UIFont.systemFont(ofSize:16);
return tip
}()
lazy var codeImageView:UIImageView= {
let imageView =UIImageView(image:UIImage(named:"front"))
imageView.frame=self.tip.frame
returnimageView
}()
override func touchesMoved(_touches:Set, with event:UIEvent?) {
let touchess = touches as NSSet
let touch:UITouch= touchess.anyObject() as! UITouch
let cententPoint = touch.location(in:codeImageView)
let rect =CGRect(x: cententPoint.x, y: cententPoint.y, width:20, height:20)
UIGraphicsBeginImageContextWithOptions(codeImageView.bounds.size,false,0)
let ref =UIGraphicsGetCurrentContext()
codeImageView.layer.render(in: ref!)
ref!.clear(rect)
let image =UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
codeImageView.image= image
}
网友评论