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

长平狐 发布于 2012/10/25 13:08
阅读 293
收藏 0

美化按钮

// 添加一个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中可以找到。


原文链接:http://www.cnblogs.com/iphone520/archive/2011/10/13/2209844.html
加载中
返回顶部
顶部