UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 50);
button.backgroundColor = [UIColor clearColor];
//設定button正常狀態下的圖片
[button setImage:[UIImage imageNamed:@"_star_normal.png"] forState:UIControlStateNormal];
//設定button高亮狀態下的圖片
[button setImage:[UIImage imageNamed:@"_star_highlighted.png"] forState:UIControlStateHighlighted];
//設定button正常狀態下的背景圖
[button setBackgroundImage:[UIImage imageNamed:@"_normal.png"] forState:UIControlStateNormal];
//設定button高亮狀態下的背景圖
[button setBackgroundImage:[UIImage imageNamed:@"_highlighted.png"] forState:UIControlStateHighlighted];
//button圖片的偏移量,距上左下右分別(10, 10, 10, 60)畫素點
button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 60);
[button setTitle:@"南瓜瓜" forState:UIControlStateNormal];
//button標題的偏移量,這個偏移量是相對於圖片的
button.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//設定button正常狀態下的標題顏色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//設定button高亮狀態下的標題顏色
[button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont systemFontOfSize:14];
[self.view addSubview:button];