开发者

iphone customizing UIButtons

how to customize the UIButton so that it will di开发者_开发问答splay other than the default button style.


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];


You can do something like this:

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];


You can use this

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];

and make event for that using

-(void)buttonToggleForHide{...}


In interface build simply change the type from rounded rect to custom and then specify a new background image.

In code:

UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom];


UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];


Set the background image on it, set Type=Custom in interface builder.


Do you mean display button with custom image? You can try this:

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


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];


@shabbir 1st select the button then press cmd+1 change the button type to custom if it right select my answer other way is that

UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom];

And if you want to call image on button then use this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜