1.空工程安装路径:Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application
直接放这里面
2.Universal包含iPhone和iPad
3.// [UIScreen mainScreen] bounds]:获取主屏幕大小,由于是MRC,一定要写autorelease,也要重写delloc方法
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible]; // 使屏幕尺寸显示
// 自己设置颜色
CGFloat red = arc4random() % 256 / 255.0; // 求0.0到1.0之间的颜色值,一定给255加点0
CGFloat green = arc4random() % 256 / 255.0;
CGFloat blue = arc4random() % 256 / 255.0;
UIColor *randomColor = [UIColor colorWithRed:red green:green blue:blue alpha:0.7];
self.window.backgroundColor = randomColor;
// 可以打印屏幕尺寸,把结构体转化为字符串
NSLog(@"%@", NSStringFromCGRect(self.window.bounds));
5.通过修改center来修改位置,比如:view通过修改自身center的点,来改变自己的位置
// 修改center
// 方法1
// view.center = CGPointMake(200, 300);
// 方法2
// view.frame = CGRectMake(150, 250, 100, 100);
#warning 点的作用不一样,不能这样访问,第一个点是访问属性,第二个点是结构体访问
// view.frame.origin.x = 100;
6.
// bounds是自身视图左上角相对于自身坐标系的位置(本视图不变,子视图相对于bounds改变),更改bounds对自身没有影响,但是会改变子视图的位置
7.添加视图方法,视图本身就是一个数组,
①:addSubview:view1 添加的时候默认往后排,第一个下标为0,依次往后
②:insertSubview:view2 atIndex:2 在第三个位置插入view2,后面的视图依次往后走
③:insertSubview:view3 aboveSubview:view2 在view2上面加入view3,这儿的意思是view3将要覆盖view2
④:insertSubview:view3 belowSubview:view2 在view2下面加入view3,这儿的意思是view2将要覆盖view3
8.管理视图层次
①:bringSubviewToFront:aView 把制定视图放在最前面把aView放在最前面
②:sendSubviewToBack: 把制定视图放在最后面
③:exchangeSubviewAtIndex:1 withSubviewAtIndex:3交换数组中第一个元素和第三个元素
④:[cView removeFromSuperview] 把cView从父视图中移除
9.视图的重要属性
9.UILable
// 1.创建
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 200)];
// 2.设置属性
nameLabel.backgroundColor = [UIColor yellowColor];
// 设置文本
nameLabel.text = @"A UIColor object represents color and sometimes opacity (alpha value). You can use UIColor objects to store color data, and during drawing you can use them to set the current fill and stroke colors.";
// 设置字体大小
nameLabel.font = [UIFont systemFontOfSize:16]; // 默认是17
// 设置文本颜色
nameLabel.textColor = [UIColor redColor];
// 设置多行 0:是多行,其他不是多行
nameLabel.numberOfLines = 0;
// 文本居中方式(左右中三种方式)
nameLabel.textAlignment = NSTextAlignmentRight;
// 换行模式:默认为:NSLineBreakByWordWrapping
nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
// 设置阴影
nameLabel.shadowColor = [UIColor blackColor];
// 阴影偏移量:(往正下方移动一个像素)
nameLabel.shadowOffset = CGSizeMake(0, 1);
// 设置边框:用点强转为CGColor
nameLabel.layer.borderColor = [UIColor cyanColor].CGColor;
// 设置边框宽度
nameLabel.layer.borderWidth = 4;
// 3.添加到视图上面
[self.window addSubview:nameLabel];
// 4.释放
[nameLabel release];
另外扩展方法:
// 设置圆角
lable.layer.masksToBounds = YES;
lable.layer.cornerRadius = 100; // 以半径为标准截园
// 旋转角度
lable.transform = CGAffineTransformMakeRotation(M_PI_2/3);
[self.window addSubview:lable];
[lable release];
4.屏幕尺寸
5.5寸:414*736
4.7寸:375*667
4寸: 320*568
3.5寸: 320*480