p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1e9421 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000; min-height: 21.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c81b13 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3c828b }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c42275 }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 }
p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #1e9421 }
p.p8 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3e1e81 }
span.s1 { }
span.s2 { font: 18.0px "PingFang SC" }
span.s3 { color: #822d0f }
span.s4 { color: #c42275 }
span.s5 { color: #000000 }
span.s6 { font: 18.0px Menlo }
span.s7 { color: #3e1e81 }
span.s8 { color: #6122ae }
span.s9 { color: #703daa }
span.s10 { color: #0435ff }
span.s11 { color: #c81b13 }
span.s12 { font: 18.0px "PingFang SC"; color: #c81b13 }
span.s13 { font: 18.0px Menlo; color: #000000 }
//
// ViewController.m
// 05-用代码创建按钮
//
// Created by vic fan on 2017/7/30.
// Copyright ? 2017年 李洪强. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
//视图加载完毕后调用,一般用来初始化(添加)控件,这个方法是系统主动调用的
//
- (void)viewDidLoad {
[super viewDidLoad];
//1.创建一个按钮对象
UIButton *headBtn = [[UIButton alloc]init];
//2.设置按钮的frame
headBtn.frame = CGRectMake(30, 30, 120, 120);
//3.添加到视图上
[self.view addSubview:headBtn];
//4.设置图片
//4.1 设置普通状态的图片
UIImage *nomalImage = [UIImage imageNamed:@"btn_01"];
[headBtn setBackgroundImage:nomalImage forState:UIControlStateNormal];
UIImage *hightImage = [UIImage imageNamed:@"btn_02"];
[headBtn setBackgroundImage:hightImage forState:UIControlStateHighlighted];
//5.设置文字
//5.1 设置普通状态下的文字
[headBtn setTitle:@"摸我吧" forState:UIControlStateNormal];
//设置高亮状态的文字
[headBtn setTitle:@"摸我干啥" forState:UIControlStateHighlighted];
//6.设置文字颜色
[headBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//设置高亮状态文字颜色
[headBtn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
//7 添加按钮的点击事件
// forControlEvents 监听的是什么事件
[headBtn addTarget:self action:@selector(benClicked) forControlEvents:UIControlEventTouchUpInside];
}
- (void)benClicked{
NSLog(@"我们快下课了");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end