1.IBAction:
1> 能保证方法可以连线
2> 相当于void
-(IBAction)
2.IBOutlet:
1> 能保证属性可以连线
@property (weak,nonatomic)IBOutlet
3.常见错误
setValue:forUndefinedKey:]: this class is not key value coding
错误原因是:连线出问题了
4.Xcode5开始的一些建议
把用于连线的一些方法和属性声明在.m文件的类扩展中
CGRect tempBounds = self.head.bounds;
// 2.改变临时属性
tempBounds.size.width += 20;
tempBounds.size.height += 20;
// 3.用临时属性覆盖原来的属性
self.head.bounds = tempBounds;
5.frame\center\bounds
1> frame:能修改位置和尺寸
不能用点语法直接修改frame属性的值
CGRect btnFrame = self.controlName.frame;
btnFrame.origin.y -= 10;
self.controlName.frame = btnFrame;
2> center:能修改位置
不能用点语法直接修改center属性的值
CGPoint tempCenter = self.head.center;
tempCenter.x += 10;
self.head.center = tempCenter;
3> bounds:能修改尺寸(x\y一般都是0)
不能用点语法直接修改bounds属性的值
CGRect tempBounds = self.head.bounds;
tempBounds.size.width += 20;
self.head.bounds = tempBounds;
6.自动生成连线信息
按住control 拖控件
7.代码动态创建控件
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"-----viewDidLoad");
// 添加
// 1.创建按钮
UIButton *btn = [[UIButton alloc] init];
// 2.添加按钮
[self.view addSubview:btn];
// 3.设置frame
btn.frame = CGRectMake(100, 100, 100, 100);
// 4.设置背景色
btn.backgroundColor = [UIColor blueColor];
// UIImage *image = [UIImage imageNamed:@"btn_01"];
// [btn setBackgroundImage:image forState:uicontrolstate];
}
// 0.开始动画
[UIView beginAnimations:nil context:nil];
// 动画持续2秒
[UIView setAnimationDuration:2.0];
// 1.取出原来的属性
CGRect tempBounds = self.head.bounds;
// 2.改变临时属性
tempBounds.size.width += 50;
tempBounds.size.height += 50;
// 3.用临时属性覆盖原来的属性
self.head.bounds = tempBounds;
// 4.提交动画
[UIView commitAnimations];