UIView的基本应用
来源:互联网 发布:linux 下启动smb服务 编辑:程序博客网 时间:2024/05/16 13:50
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; #if 0 //UI-view 视图,基础单元(UI的基类) UIView * view1 = [[UIView alloc]init]; //1.位置和大小 2.加载在父视图中 //320x480px 状态栏 20px //位置大小 //view1.frame=self.window.bounds;整个屏幕 view1.frame = CGRectMake(10, 30, 300, 440); //设置背景颜色 view1.backgroundColor = [UIColor blueColor]; [self.view addSubview:view1]; //同一个父视图中后加入的控件盖在上面 UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)]; view2.backgroundColor = [UIColor redColor]; [self.view addSubview:view2]; //坐标是相对父视图来进行设置的,遮挡关系是根据最大的父视图进行判定, //再逐一判定每个子视图的子视图 UIView * view3 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)]; view3.backgroundColor = [UIColor orangeColor]; [view1 addSubview:view3]; //调整遮挡关系 //1.将某一个子视图放在最上层 [self.view bringSubviewToFront:view1]; //2.将某一个子视图放在最下层 [self.view sendSubviewToBack:view1]; //3.交换两个层的视图 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; //4.将子视图加到某一个子视图下层 UIView * view4 = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)]; view4.backgroundColor = [UIColor cyanColor]; [self.view insertSubview:view4 belowSubview:view2]; //5.将子视图加入到某个子视图上方 UIView * view5 = [[UIView alloc]initWithFrame:CGRectMake(5, 10, 100, 30)]; view5.backgroundColor = [UIColor brownColor]; [self.view insertSubview:view5 aboveSubview:view1]; //6.将子视图加入到特定层 UIView * view6 = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)]; view6.backgroundColor = [UIColor whiteColor]; [self.view insertSubview:view6 atIndex:4]; NSLog(@"%f %f %f %f",view1.frame.origin.x,view1.frame.origin.y,view1.frame.size.width,view1.frame.size.height); NSLog(@"%f %f %f %f",view1.bounds.origin.x,view1.bounds.origin.y,view1.bounds.size.width,view1.bounds.size.height);//只能打印宽高 //center NSLog(@"%f %f",view1.center.x,view1.center.y); //获得父视图 UIView * superView = view1.superview; NSLog(@"%@",superView); //获得子视图(多个) NSArray * subViewsaArray = view1.subviews; NSLog(@"%@",subViewsaArray); //tag - 标识 view1.tag = 1001; //通过tag找到子视图 //UIWindow * tagView = [_window viewWithTag:1001]; //tagView.backgroundColor = [UIColor lightGrayColor]; /* < iOS6 UIView 自适应来做屏幕适配 iOS6~iOS8 AutoLayout iOS8> AutoLayout+ SizeClass */ #endif UIView * backView = [[UIView alloc]initWithFrame:CGRectMake(110, 200, 100, 100)]; backView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:backView]; backView.tag = 1002; //准许子视图跟随改变 backView.autoresizesSubviews = YES; UIView * topView = [[UIView alloc]initWithFrame:CGRectMake(25, 25, 50, 50)]; topView.backgroundColor = [UIColor greenColor]; //2.设置子视图跟随方式 topView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;//多种变化方式用| [backView addSubview:topView]; //定时器 [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeTick) userInfo:nil repeats:YES]; //剪裁超出俯视图范围的子视图// view1.clipsToBounds = YES; // Do any additional setup after loading the view, typically from a nib.}- (void)timeTick { UIView *backView = [self.view viewWithTag:1002]; backView.frame = CGRectMake(backView.frame.origin.x-2, backView.frame.origin.y-2, backView.frame.size.width+4, backView.frame.size.height+4); }
1 0
- UIView的基本应用
- UIView的基本使用
- UIView的基本控件
- UIview的一些基本方法
- 8.UIView的基本使用
- UIView.layer的基本属性
- UIView属性clipsTobounds的应用
- UIView属性clipsTobounds的应用
- UIView属性clipsTobounds的应用
- UIView属性clipsTobounds的应用)
- UIView属性clipsTobounds的应用
- UIview基本
- UIView的一些基本方法理解
- UIView的一些基本方法理解
- IOS开发之UIView的基本使用
- iOS文档-UIView的基本属性
- ios--UIView的基本属性和自定义
- 2.4 UIView的基本属性和自定义
- 工厂模式:封装对象的创建(二、多态工厂)
- js判断是否为安卓设备或微信浏览器
- 解决使用PullToRefreshListView找不到setOnItemLongClickListener方法的问题
- linux 下忘记 root用户密码修改
- 电源芯片选择DC/DC还是LDO?
- UIView的基本应用
- 博客迁移了
- C#类型转换总结(一)
- Ios和tvos按需请求资源简介
- iOS-获取Wifi的IP和名字
- IOS9中各种微信或QQ分享SDK显示为安装软件
- android 4.4 读写问题
- IOS开发:对TextField或TextView添加文字限制
- css3动画效果