8.纯代码:按钮头像 版本2.0
备注:增加了点击按钮变换头像的功能
--------------- ViewController.m ---------------
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc] init];
btn.frame = CGRectMake(100, 100, 100, 100);
[btn setBackgroundImage:[UIImage imageNamed:@"btn_01"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];
[btn setTitle:@"你摸我啊" forState:UIControlStateNormal];
[btn setTitle:@"摸我干嘛" forState:UIControlStateHighlighted];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
[self.view addSubview:btn];
}
@end