在view上画一个button,自定义其按下和松开后的样式

来源:互联网 发布:百度云搜索源码 编辑:程序博客网 时间:2024/05/16 15:35

button选custom

然后在viewDidLoad()中:

 

 

 

//普通状态下:
UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];    UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];    [self.doSomething setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];    //按下时高亮:    UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];    UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];    [self.doSomething setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];