2.ios拖控件

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];
}


8.简单的过度动画


   // 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];




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值