1. 代码操作按钮:
UIButton *rexianBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 210, 190, 60)];
[rexianBtn setBackgroundImage:[UIImage imageNamed:@"shou_rexian"] forState:UIControlStateNormal];
[rexianBtn addTarget:self action:@selector(menuButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:rexianBtn];
2. 美化按钮:
下面的代码摘自http://www.cnblogs.com/iphone520/archive/2011/10/13/2209844.html
// 添加一个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];