iphone程序里自定义专业的button图片

标题名字真难取阿,直接在ib里添加也可以,但是对于button的各种状态切换不灵活。处理拉伸也不好。 
用以下方法比较专业: 
UIImage *buttonImageNomal = [UIImage imageNamed:@"whiteButton.png"]; 
UIImage *stretchableButtonImageNomal = [buttonImageNomal stretchableImageWithLeftCapWidth:15 topCapHeight:0]; 
[button setBackgroundImage:stretchableButtonImageNomal forState:UIControlStateNormal]; 
 
UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"]; 
UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:15 topCapHeight:0]; 
[button setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted]; 

源地址:http://www.cocoachina.com/blog/article.php?type=blog&itemid=29

你可能感兴趣的:(iPhone)