开发技巧-改变按钮属性3部曲

mac2022-06-30  25

#pragma mark 向上走 - (IBAction)up {     // 不允许直接修改  对象 的 结构体属性 的成员         // 允许直接 对象 的 结构体 属性         CGRect tempFrame = self.head.frame;     tempFrame.origin.y -= 10;     self.head.frame = tempFrame; } #pragma mark 放大 - (IBAction)big; {     // 1.取出原来的属性     CGRect tempFrame = self.head.frame;         // 2.改变临时属性     tempFrame.size.width += 20;     tempFrame.size.height += 20;         // 3.用临时属性覆盖原来的属性     self.head.frame = tempFrame; }     通过修改控件的frame属性就可以修改控件在屏幕上的位置和尺寸

 

比如点击“向上”按钮,让按钮的y值减小即可

- (IBAction)top:(UIButton*)sender {

    CGRectbtnFrame = self.headBtn.frame;

    btnFrame.origin.y -= 10;

    self.headBtn.frame = btnFrame;

}

 

下面代码是错误的,OC语法规定:不允许直接修改对象的结构体属性的成员   self.headBtn.frame.origin.y -= 10;

转载于:https://www.cnblogs.com/ljwiOS/p/5223981.html

最新回复(0)