9.纯代码:按钮头像 版本3.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];

    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];//监听

    [self.view addSubview:btn];

}


- (void) btnClick

{

    NSLog(@"btnClick");

}


@end

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