UI笔记

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

//创建视图控件。

@property(strong,nonatomic)UIView *myview;

@end

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

    

//    初始化视图

    self.myview=[[UIView alloc]initWithFrame:(CGRectMake(100, 100, 100, 200))];

    

    

    

//    2背景色

    self.myview.backgroundColor=[UIColor redColor];

    

    

    

    

//    3.添加子视图到view上.

    [self.view addSubview:self.myview];

//    4.初始化view的颜色。

    self.view.backgroundColor=[UIColor purpleColor];

    

//    5.输出view的尺寸

//    SStringFromCGRect((CGRect rect))将结构体转换成字符串。

    CGRect rectview=  self.view.frame;

    NSLog(@"%@",NSStringFromCGRect(rectview));

//    相对父视图的坐标位置

    NSLog(@"myView.frame:%@",NSStringFromCGRect(self.myview.frame));

    

//    bounds 只是显示当前视图的大小  和位置无关

    NSLog(@"myView.bounds:%@",NSStringFromCGRect(self.myview.bounds));

    

    

//    center 控件相对于父视图的中心点坐标.

    NSLog(@"myView.center:%@",NSStringFromCGPoint(self.myview.center));

    

//重新设置视图的中心点

    self.myview.center=CGPointMake(300, 500);

    

//改变视图的边界。用bounds。

    self.myview.bounds=CGRectMake(0, 0, 100, 150);

    

//    水平方向移动100

    self.myview.transform=CGAffineTransformMakeTranslation(-100, 0);

//    垂直方向

    

    self.myview.transform=CGAffineTransformMakeRotation(M_PI_4);

    self.myview.transform = CGAffineTransformRotate(self.myview.transform, M_PI_2);

    

//    

//    还原

@property(strong,nonatomic) UIView *aview;

@property(strong,nonatomic) UIView *bview;

@property(strong,nonatomic) UIView *cview;

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    

    self.aview=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];

    self.aview.backgroundColor=[UIColor redColor];

    self.bview=[[UIView alloc]initWithFrame:CGRectMake(150, 150, 200, 200)];

    self.bview.backgroundColor=[UIColor blackColor];

    self.cview=[[UIView alloc]initWithFrame:CGRectMake(200, 200, 200, 200)];

    self.cview.backgroundColor=[UIColor blueColor];

    

    

    

    [self.view addSubview:self.aview];

//    [self.view insertSubview:self.bview aboveSubview:self.aview];

    [self.view addSubview:self.bview];

    [self.view addSubview:self.cview];

//    yichu

//    [self.bview removeFromSuperview];

    

//    交换位置

//    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:3];

    

//    将子视图放到最后

//    [self.view sendSubviewToBack:self.cview];

//    将子视图放到最前

    [self.view bringSubviewToFront:self.aview];

    

原文地址:https://www.cnblogs.com/tianlianghong/p/5252265.html