//通知自定義的view重新繪制圖形
[selfsetNeedsDisplay];
setNeedsDisplay方法:重新繪制,調用這個方法就會通知自定義的view重新繪制畫面,調用drawRect:。
drawRect:方法不能由我們自己手動調用,只能由系統來調用。
drawRect:調用的時機:當第一次顯示或者一個重繪事件發生時調用。
UIButton*bb = [UIButtonbuttonWithType:UIButtonTypeCustom];
bb.frame=CGRectMake(0,0,200,300);
[selfaddSubview:bb];
UIBezierPath*sk = [UIBezierPathbezierPathWithRoundedRect:CGRectMake(0,0,100,200)byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeftcornerRadii:CGSizeMake(10,10)];
CAShapeLayer*pat = [[CAShapeLayeralloc]init];
pat.frame=CGRectMake(0,0,120,220);
pat.path= sk.CGPath;
bb.layer.mask= sk;