//通知自定義的view重新繪制圖形
[selfsetNeedsDisplay];
setNeedsDisplay方法:重新繪制赃绊,調(diào)用這個(gè)方法就會(huì)通知自定義的view重新繪制畫面羡榴,調(diào)用drawRect:。
drawRect:方法不能由我們自己手動(dòng)調(diào)用校仑,只能由系統(tǒng)來(lái)調(diào)用迄沫。
drawRect:調(diào)用的時(shí)機(jī):當(dāng)?shù)谝淮物@示或者一個(gè)重繪事件發(fā)生時(shí)調(diào)用。
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;