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];
?