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

posted @ 2015-08-01 14:49  我要选李白  阅读(163)  评论(0编辑  收藏  举报