1. UIView的基本用法
//打印屏幕的宽和高CGRect screenBounds = [[UIScreen mainScreen] bounds];NSLog(@"%f, %f", screenBounds.size.width, screenBounds.size.height);//创建一个UIView//UIView表示一个矩形区域UIView *v1 = [[UIView alloc] init];//1.确定大小CGRect rect = CGRectMake(0, 0, 100, 100);v1.frame = rect;//2.确定颜色v1.backgroundColor = [UIColor redColor];//3.添加到窗口 [self.window addSubview:v1];//以下两句创建UIView可以简写为一句,用initWithFrame:CGRectMake//UIView *v4 = [[UIView alloc] init];//v4.frame = CGRectMake(320 - 100, 480 - 100, 100, 100);UIView *v4 = [[UIView alloc] initWithFrame:CGRectMake(320 - 100, 480 - 100, 100, 100)];v4.backgroundColor = [UIColor yellowColor];[self.window addSubview:v4];
2. UILable基本用法
//标签控件,主要用来做信息提醒UILabel *label = [[UILabel alloc] init];label.frame = CGRectMake(10, 20, 300, 30);//label.backgroundColor = [UIColor blackColor];//设置显示内容label.text = @"Sent";//设置字体和字体大小//1.获取当前系统所有支持的字体NSArray *allFont = [UIFont familyNames];NSLog(@"allFont = %@", allFont);
//2.选择使用其中一个字体,系统默认字体大小为17UIFont *font = [UIFont fontWithName:@"Party LET" size:40];
//3.将字体使用到label上label.font = font;//设置字体颜色label.textColor = [UIColor redColor];//对齐方式//NSTextAlignmentLeft 左对齐(默认)//NSTextAlignmentRight 右对齐//NSTextAlignmentCenter 居中label.textAlignment = NSTextAlignmentCenter;//设置文字阴影//1.阴影大小//宽高可以理解为偏移量,是相对于label的第一个字的偏移// width height// + + 右下角// + - 右上角// - + 左下角// - - 左上角// + 0 右边// - 0 左边// 0 + 下边// 0 - 上边CGSize offset = CGSizeMake(0, -5);label.shadowOffset = offset;//2.阴影颜色label.shadowColor = [UIColor brownColor];//设置行数,默认为1行label.numberOfLines = 10 /*行数,如果 == 0 表示任意多行*/;//自动调整字体,以显示完所有内容,YES为自动调整label.adjustsFontSizeToFitWidth = NO;[self.window addSubview:label];