Button

•通过修改控件的frame属性就可以修改控件在屏幕上的位置和尺寸
•比如点击“向上”按钮,让按钮的y值减小即可

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

    CGRect btnFrame = self.headBtn.frame;

    btnFrame.origin.y -= 10;

    self.headBtn.frame = btnFrame;

}

//在Xcode6以后编译成功

•下面代码是错误的,OC语法规定:不允许直接修改对象的结构体属性的成员

self.headBtn.frame.origin.y -= 10;

// 创建一个自定义的按钮

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

// 默认状态的背景

[btn setBackgroundImage:[UIImage imageNamed:@"btn_01"] forState:UIControlStateNormal];

// 默认状态的文字

[btn setTitle:@“点击我" forState:UIControlStateNormal];

// 默认状态的文字颜色

[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

在iOS开发中,想实现一些小动画是非常容易的
系统会根据某个属性值的改变自动形成动画
比如x值本来是10,然后x值突然改为了100,系统会通过平移动画的方式让x值慢慢从10变到100
简易动画大致有2种方式:
头尾式

[UIView beginAnimations:nil context:nil];

/** 需要执行动画的代码 **/

[UIView commitAnimations];

Block式

[UIView animateWithDuration:0.5 animations:^{

    /** 需要执行动画的代码 **/

}];

通过以下属性可以修改控件的位置
frame.origin
center
通过以下属性可以修改控件的尺寸
frame.size
bounds.size
 
 
利用transform属性可以修改控件的位移(位置)、缩放、旋转
 
创建一个transform属性
CGAffineTransform CGAffineTransformMakeTranslation(CGFloat tx,  CGFloat ty) ;
CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy);
CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle)

(angle是弧度制,并不是角度制)

在某个transform的基础上进行叠加
CGAffineTransform CGAffineTransformTranslate(CGAffineTransform t, CGFloat tx, CGFloat ty);
CGAffineTransform CGAffineTransformScale(CGAffineTransform t, CGFloat sx, CGFloat sy);
CGAffineTransform CGAffineTransformRotate(CGAffineTransform t, CGFloat angle);
•清空之前设置的transform属性

view.transform = CGAffineTransformIdentity;

为自己写的button 注册一个 触发方法 为back  [bt addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

 @font-face { font-family: "宋体"; }@font-face { font-family: "宋体"; }@font-face { font-family: "@宋体"; }p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0cm 0cm 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: "Times New Roman"; }.MsoChpDefault { font-size: 10pt; }div.WordSection1 { page: WordSection1; }

开启用户交互功能 比如imageview.userInteractionEnabled=YES;

会影响按钮内部的所有内容(里面的imageView和titleLabel)top left bottom right 四个方向的距离

Button  shareBtn

shareBtn.contentEdgeInsets =UIEdgeInsetsMake(a,b,c,d);

只影响内部的title

shareBtn.titleEdgeInsets = UIEdgeInsetsmake()

原文地址:https://www.cnblogs.com/Opaser/p/4595178.html