IOS中调整UI控件位置和尺寸

1.frame(修改位置和尺寸):以父控件左上角为坐标原点,在其父控件中的位置和尺寸。

    //frame属性中的坐标点不能直接修改
    CGRect tempFrame = self.v.frame;  // 1.取出原来的属性
    
tempFrame.origin.y+=10;//2.坐标点y加10 相当于向下移动10

self.v.frame=tempFrame;//3.赋值

2.bounds(修改尺寸):以自己左上角为坐标原点(x=0,y=0),控件的位置和尺寸。

    //因为其始终以自身左上角为坐标原点,所以只能修改尺寸,修改位置不会改变
    CGRect tempBounds   = self.v.bounds;
tempBounds.size.height
-=10;
tempBounds.size.width
-=10;
self.v.bounds
=tempBounds;

3.center(修改位置):以父控件的左上角为坐标原点,其控件中点的位置。

    CGPoint tempCenter = self.v.center;
    
tempCenter.y
-= 10;
self.v.center
= tempCenter;

4.transform(修改位置、尺寸、旋转角度)

    //修改位置
    UIButton *v = (UIButton *)[self.view viewWithTag:1];
    v.transform=CGAffineTransformTranslate(v.transform, 0, -10);


    //修改尺寸
    v.transform=CGAffineTransformScale(v.transform, 2, 2);//增大倍数


    //修改角度// 角度是正数:顺时针, 角度是负数:逆时针
   v.transform=CGAffineTransformRotate(v.transform, -M_PI_4);  //向左旋转45°
原文地址:https://www.cnblogs.com/yangjingqi/p/4889913.html