2011-11-30 39 views

回答

0

來實現這一目標最簡單的方法是使用:

UIButton *myButton=[UIButton buttonWithType:UIButtonTypeCustom]; 
[myButton setFrame:CRectMake(0, 0, imWidth, imHeight)]; 
[myButton setBackgroundImage:[UIImage imageNamed:@"shabadabada.png"] forState:UIControlStateNormal]; 

這將讓你一個簡單的按鈕...雖然它實際上沒有形如「shabadabada」(:P),這將是一個平方的按鈕。

要做到真正的自定義形狀「按鈕,」你必須從UIView類來實現:

-(void) drawRect:(CGRect)rect; 

而且你必須繪製由點你的形狀來看,這裏是做this一個簡單的指南。

而且還可以採用如下方法作出迴應:

– touchesBegan:withEvent: 
– touchesMoved:withEvent: 
– touchesEnded:withEvent: 
– touchesCancelled:withEvent: 

或者就是:

– addGestureRecognizer: 
相關問題