[IOS] iphone开发之[美化按钮]

美化按钮

//添加一个button,美化按钮
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.frame = CGRectMake(40, 300, 100, 30);

UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];
UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
//[btn1 setImage:stretchableButtonImageNormal forState:UIControlStateNormal];
[btn1 setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal]; //set backgroundImage:

UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];
UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[btn1 setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];

[self.view addSubview:btn1];

解说一下:whiteButton.png    blueButton.png  图片在苹果官方网站提供的DEMO:UICatalog中可以找到。

posted @ 2011-10-13 10:27  松花江以南  阅读(1792)  评论(0编辑  收藏  举报