2011-05-10 30 views
0

如何自定義UIButton,以便它將顯示除默認按鈕樣式之外的其他東西。iphone定製UIButtons

+0

@ shabbir-ahmed - 請標記正確的答案。它激勵用戶回答更多。此外,它可以幫助用戶決定他們應該積極回答您的問題。 – iMatoria 2011-05-13 05:39:15

回答

0

在界面構建中,只需將類型從圓角矩形更改爲自定義,然後指定新的背景圖像。

在代碼:

UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom]; 
0
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; 
0

設置在界面生成器在其上的背景圖像,設定類型=定製。

0

@shabbir 1日選擇按鈕,然後按CMD + 1的變化按鈕類型定製 如果是正確的選擇我的答案 其他方式是

UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom]; 

如果你想打電話按鈕圖像,然後使用這個

UIButton *button = [[UIButton alloc]initWithImage:[UIImage imageNamed:@"button.png"]]; 
[button release]; 
0

你的意思是顯示按鈕與自定義圖像?你可以試試這個:

UIButton *button = [[UIButton alloc]initWithImage:[UIImage imageNamed:@"button.png"]]; 
[button release]; 
1

你可以做這樣的事情:

UIImage *btnImage = [UIImage imageNamed:@"images-01.png"]; 

UIButton *btnGo = [UIButton buttonWithType:UIButtonTypeCustom]; 
btnGo.frame = CGRectMake(85,123, 100, 26); 
btnGo.backgroundcolor = [UIColor clearColor]; 
btnGo. setImage:btnImage forState: UIcontrolStateNormal]; 
[btnGo.titleLabel setFont: [UIFont systemFontOfSize:14]]; 
btnGo addTarget: self action:@selector(btnGoClicked) forControlEvents: UIControlEventTouchUpInside]; 
2
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; 
btn.frame = CGRectMake(10.0, 20.0, 50.0, 50.0); // You can change the x, y, width, height. 
[btn setImage:[UIImage imageNamed:@"img.png"] forState:UIControlStateNormal]; 
[self.view addSubView:btn]; 
0
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; 
button.frame = urRequiredFrame; 
[button setImage:yourCustomImage forState:UIControlStateNormal]; 
button addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside]; 

[self.view addSubView:button]; 
1

您可以使用此

UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
customButton.frame = CGRectMake(899, 5, 82, 55); 
customButton.tag = 123; 
[customButton addTarget:self action:@selector(buttonToggleForHide) forControlEvents:UIControlEventTouchUpInside]; 
[self.view addSubview:customButton]; 

,使事件,使用

-(void)buttonToggleForHide{...}