UIview lianxi
// 创建一个和屏幕大小相同的window,记住[UIScreen mainScreen].bounds 是获取当前屏幕大小
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// 设置window的背景颜色
self.window.backgroundColor = [UIColor grayColor];
// 将window设置上,并让window显示
[self.window makeKeyAndVisible];
/*
// 打印屏幕大小,使用NSStringFromCGRect()
NSLog(@"%@", NSStringFromCGRect([UIScreen mainScreen].bounds));
// 添加一小块视图到屏幕上
// 1. 申请空间,并初始化大小
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
// 2. 设置view相关属性
view.backgroundColor = [UIColor whiteColor];
view.bounds = CGRectMake(20, 0, 200, 200);
// 3. 添加到window上
// 添加view到_window上,给_window发送消息
// 将一个view添加到window上时,view的引用计数会+1
[_window addSubview:view];
// 4. 发送一次release消息
[view release];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
view2.backgroundColor = [UIColor redColor];
[view addSubview:view2];
[view2 release];
// 使用中心点更改view的位置
// view.center = CGPointMake(320 / 2, 568 / 2);
// NSLog(@"%@", NSStringFromCGPoint(view.center));
// view2.center = CGPointMake(view.frame.size.width / 2, view.frame.size.height / 2);
// NSLog(@"%@", NSStringFromCGPoint(view2.center));
*/
//view1 蓝色
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
view1.backgroundColor = [UIColor blueColor];
view1.tag = 1000;
[_window addSubview:view1];
[_window viewWithTag:1000].backgroundColor = [UIColor yellowColor];//根据tag值,取出view 设置
[view1 release];
//view2 红色
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(80, 20, 100, 400)];
view2.backgroundColor = [UIColor redColor];
view2.tag = 1001;
[_window addSubview:view2];
//[_window insertSubview:view2 belowSubview:view1];//将红 插到 蓝的底下
[view2 release];
//view3 紫色
UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)];
view3.backgroundColor = [UIColor purpleColor];
view3.tag = 1002;
view3.hidden = NO;
view3.center = CGPointMake(160, 160);//设置中心点属性
[_window addSubview:view3];
//[_window insertSubview:view3 atIndex:1];
[view3 release];
// 将view提到最上层
//[_window bringSubviewToFront:view2];
// 将view放到最下层
// [_window sendSubviewToBack:view2];
// 将view2从父视图上移除
//[view2 removeFromSuperview];
NSLog(@"%@", view1.superview);
NSLog(@"%@", _window.subviews);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 350, 200, 40)];
label.text = @"cai bi";
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:40];
[_window addSubview:label];
[label release];
//
[_window viewWithTag:1000].alpha = 0.5;
最新文章
- [原创] C# dynamic拼接Json串
- mybatis中#{}与${}的差别(如何防止sql注入)
- 运用webkit绘制渲染页面原理解决iscroll4闪动的问题
- 几个ES6新特性
- 数据库SQL优化总结
- Unity State Machine
- Yii2 事务
- HTML图片元素(标记)
- python bottle框架(WEB开发、运维开发)教程
- win10 ie11 以管理员身份运行才正常
- 部署到Linux使用VS Code 开发.NET Core 应用程序
- 10324 - Zeros and Ones
- [转]Mysql explain用法和性能分析
- 【转载】SQL Server行转列,列转行
- [react] React 新手必须知道的 N 件事
- Java的IO系统
- Java汉字乱码问题
- 第四章:4.2MySQL 权限系统介绍
- k个一组翻转链表
- Android 流媒体技术见解
热门文章
- c# 发送邮件、附件 分类: C# 2014-12-17 16:41 201人阅读 评论(0) 收藏
- Windows Live Writer的Markdown插件
- win10安装MySQL
- win8系统添加开机自启动软件的方法(转)
- UML类图详细介绍
- [Redux] Supplying the Initial State
- String是java中的基本数据类型吗
- [转] git修改author
- Android中你应该知道的设计模式
- css考核点整理(十三)-jpg/png/gif等图片类型区别