UI界面的一些简单控件

虽然都是代码 , 但是基本都有注释。

 

#import "ViewController.h"

@interface ViewController ()

/**
 *  创建视图
 */
@property(strong,nonatomic) UIView *myView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    /**
     初始化视图
     */
    self.myView=[[UIView alloc]initWithFrame:CGRectMake(0, 30, 200, 200)];
    /**
     *  背景色
     */
    self.myView.backgroundColor=[UIColor colorWithRed:1.000 green:0.416 blue:0.882 alpha:1.000];
    /**
     *  添加子视图到view上
     */
    [self.view addSubview:self.myView];
    self.view.backgroundColor=[UIColor colorWithRed:0.330 green:1.000 blue:0.096 alpha:1.000];
    CGRect rec=self.view.frame;
    /**
     *  frame 相对父视图的坐标位置
     */
    NSLog(@"view.frame:%@",NSStringFromCGRect(rec));
    // bounds  只显示当前视图的大小  和位置无关(0,0)
    NSLog(@"myView.bounds:%@",NSStringFromCGRect(self.myView.bounds));
    //   center  控件相对于父视图的中心点坐标
    NSLog(@"%@",NSStringFromCGPoint(self.myView.center));
    /**
     *  设置视图的中心点坐标
     */
    self.myView.center=CGPointMake(300, 350);
    /**
     *  改变视图的边界
     */
    self.myView.bounds=CGRectMake(0, 0, 50, 50);
    /**
     *  CGAffineTrans  让你在原有的视图上进行各种变换
     */
    self.myView.transform=CGAffineTransformMakeTranslation(50, 0);
     
    
    
    
 }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.aview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    self.aview.backgroundColor=[UIColor colorWithRed:1.000 green:0.305 blue:0.259 alpha:1.000];
    self.bview=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
    self.bview.backgroundColor=[UIColor blackColor];
    self.cview=[[UIView alloc]initWithFrame:CGRectMake(200, 200, 200, 200)];
    self.cview.backgroundColor=[UIColor colorWithRed:0.558 green:0.977 blue:0.584 alpha:1.000];
    //添加子视图abc
    [self.view addSubview:self.aview];
    [self.view addSubview:self.bview];
    [self.view addSubview:self.cview];
    //插入指定视图 ,在XXX下面
    [self.view insertSubview:self.bview belowSubview:self.aview];
    //在XXX上面
    [self.view insertSubview:self.bview aboveSubview:self.aview];
    //在指定插入位置插入子视图
    [self.view insertSubview:self.bview atIndex:2];
    //在父视图中移除子视图
    [self.bview  removeFromSuperview];
    //交换子视图的索引位置
    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];
    //将子视图放在最后
    [self.view sendSubviewToBack:self.cview];
    //将子视图放在最前
    [self.view bringSubviewToFront:self.aview];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

#import "ViewController.h"

@interface ViewController ()
@property(strong,nonatomic) UILabel *labelName;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.labelName=[[UILabel alloc]initWithFrame:CGRectMake(0, 100, 400, 200)];
    self.labelName.backgroundColor=[UIColor redColor];
    //输入文本
    self.labelName.text=@"11135135135135135135";
    //文本颜色
    self.labelName.textColor=[UIColor blueColor];
    //文本对齐方式(居中)
    self.labelName.textAlignment=NSTextAlignmentCenter;
    //文本字体放大或缩小
    self.labelName.font=[UIFont systemFontOfSize:20 weight:20];
    //显示行数
    self.labelName.numberOfLines=10;
    
    [self.view addSubview:self.labelName];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

posted on 2016-03-07 20:19  无梦为安  阅读(466)  评论(0编辑  收藏  举报

导航