UIView
//創建window和當前屏幕一樣大的
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//設置window顏色
? ?self.window.backgroundColor = [UIColor whiteColor];
//設置window可見
? ?[self.window makeKeyAndVisible];
//xcode7 崩潰解決
? ?self.window.rootViewController = [[UIViewController alloc] init];
//內存管理
? ?[_window release];
//1.創建視圖
? ?UIView *aview = [[UIView alloc]init];
? ?//設置frame
? ?aview.frame = CGRectMake(0, 0, 100, 100);
? ?//設置屬性
? ?aview.backgroundColor = [UIColor whiteColor];
? ?//添加到父視圖(window)上顯示
? ?[self.window addSubview:aview];
? ?//內存管理
? ?[aview release];
//2.中心顯示
? ?//數值設置(絕對坐標)
? ?aview.center = CGPointMake(375/2, 667/2);
? ?//通過其他控件的位置設置(相對坐標)
? ?aview.center = self.window.center;
//view屬性
? ?//顯示/隱藏
? ?aview.hidden = NO;
? ?//透明度 alpha(0-1的浮點數)
? ?aview.alpha = 1;
? ?//動畫
? ?[UIView animateWithDuration:1 animations:^{
? ? ? ?aview.alpha = 0;
? ? ? ?aview.frame = CGRectMake(0, 0, 200, 200);
? ?}];
? ?//標記值 tag
? ?aview.tag = 1000;
? ?//通過標記尋找視圖
? ?UIView *tempView = [self.window viewWithTag:1000];
? ?tempView.backgroundColor = [UIColor yellowColor];
? ?//一個視圖中只有一個父視圖 ?可以有若干個子視圖
? ?//視圖從父視圖上移除
? ?[aview removeFromSuperview];
//添加父視圖
? ?//frame 設置時以父視圖左上角為坐標原點
? ?[aview addSubview:tempView];
? ?//子視圖自身的hidden和alpha只影響自己
? ?//父視圖的hidden和alpha會影響 自身和所有子視圖
//層次關系操作 使用父視圖操作
? ?//把子視圖拿到前端
? ?[self.window bringSubviewToFront:aview];
? ?//把子視圖送到最后
? ?[tempView sendSubviewToBack:aview];
//定時器NSTimer
? ?//每隔一段時間讓某某做某事
? ?//參數1:時間間隔
? ?//參數2:moumou
? ?//參數3:某事
? ?[NSTimer scheduledTimerWithTimeInterval:6 target:self selector:@selector(haha) userInfo:nil repeats:YES];
UIButton
//1.創建(便利構造器)
? ?UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
//2.設置frame
? ?btn.frame = CGRectMake(100, 100, 100, 100);
//3.設置屬性
? ?btn.backgroundColor = [UIColor redColor];
? ?[self.window addSubview:btn];
//4.綁定按鈕點擊事件(按鈕被點擊時能夠觸發一個方法)
? ?//參數1: target 目標(調用方法的人)
? ?//參數2: action 動作(調用的方法)
? ?//參數3: events 事件(方法的觸發條件)
// ?UIControlEventTouchUpInside ?控制事件之 觸摸頂端按下去
? ?//:參數標志(之后一定會跟隨一個參數)
? ?[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
//5.添加父視圖
? ?[self.window addSubview:btn];
//按鈕文字
? ?[btn setTitle:@"正常" forState:UIControlStateNormal];
? ?//按鈕長按就是高亮狀態
? ?[btn setTitle:@"高亮" forState:UIControlStateHighlighted];
? ?//高亮時按鈕顯示觸摸
? ?btn.showsTouchWhenHighlighted = YES;
UILabel
? ?//1.創建+frame
? ?UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
? ?//2.屬性設置
? ?label.backgroundColor = [UIColor yellowColor];
? ?//3.添加父視圖
? ?[self.window addSubview:label];
? ?//4.內存管理
? ?[label release];
//label文字相關的屬性
? ?//顯示文字 ?text
? ? ?//默認 ?左對齊/居中顯示/文本黑色/行數為1/背景透明色
? ?label.text = @"這是一個label";
? ?//文本顏色
? ?label.textColor = [UIColor redColor];
? ?//文本對齊方式
? ?label.textAlignment = NSTextAlignmentCenter;
? ?//文本斷行模式(文本省略方式)
? ?label.lineBreakMode = NSLineBreakByTruncatingMiddle;
? ?//文本行數 ?numberOfLines
? ?//默認為1 ?為0時行數不限
? ?label.numberOfLines = 0;
? ?//字體 ?font
? ?label.font = [UIFont fontWithName:@"" size:20];
? ?//陰影 ?shadow
? ?label.shadowColor = [UIColor grayColor];
? ?//陰影偏移量
? ?label.shadowOffset = CGSizeMake(2, 10);
UITextField
?//創建UITextField
? ?UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
?//設置背景顏色
? ?textField.backgroundColor = [UIColor grayColor];
?//添加父視圖
? ?[self.window addSubview:textField];
?//內存管理
? ?[textField release];
//文本控制
? ?//占位字符串 ?placehholder
? ?textField.placeholder = @"請輸入:";
? ?//輸入控制
? ? ?//是否可用 ?enabled
? ?textField.enabled = YES;
? ?//安全文本輸入 ?secureTextEntry(密碼輸入模式)
? ?textField.secureTextEntry = YES;
//鍵盤樣式 keyboardType
? ?textField.keyboardType = UIKeyboardTypeDefault;
//return (回車按鍵)樣式
? ?textField.returnKeyType = UIReturnKeyGoogle;
? ?//開始輸入時清空
? ?textField.text = @"輸入內容";
? ?textField.clearsOnBeginEditing = YES;
//外觀控制
? ?//輸入框樣式
? ?textField.borderStyle = UITextBorderStyleNone;
? ?//邊框寬度
? ?textField.layer.borderWidth = 1;
? ?//邊框顏色
? ?textField.layer.borderColor = [UIColor cyanColor].CGColor;
? ?//切圓角(圓形:正方形邊長的一半)
? ?textField.layer.cornerRadius = 20;
? ?textField.layer.cornerRadius = textField.frame.size.width / 2;
? ?//清除按鈕
? ?textField.clearButtonMode = UITextFieldViewModeAlways;
//UIVC
? ?//添加圖片
? ?//相對路徑 ?修改之后仍然可以正常顯示
? ?//絕對路徑 ?如果文件位置修改 就找不到了
? ?// ? ?imgView.image = [UIImage imageNamed:@"color.jpg"];
? ?//收獲路徑(動態變化的絕對路徑)
? ?//參數1:文件名
? ?//參數2:文件后綴
? ?NSString *path = [[NSBundle mainBundle]pathForResource:@"color" ofType:@"jpg"];
? ?imgView.image = [UIImage imageWithContentsOfFile:path];
? ?//圓角
? ?imgView.layer.cornerRadius = imgView.frame.size.width/2;
? ?//根據邊界把多余部分切掉
? ?imgView.clipsToBounds = YES;
鍵盤回收
//1.簽訂系統協議
? ?@interface AppDelegate ()
? ?@end
? ?UITextField *tf1 = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 40)];
? ?tf1.backgroundColor = [UIColor redColor];
? ?[self.window addSubview:tf1];
? ?[tf1 release];
//2.設置代理人
? ?tf1.delegate = self;
? ?tf1.tag = 1000;
//3.協議方法
? ?//參數(textField):當前觸發協議方法的輸入框
? ?-(BOOL)textFieldShouldReturn:(UITextField *)textField{
? ? ? ?UITextField *tf1 = [self.windowviewWithTag:1000];
? ? ? ?//失去第一響應者(點擊return 鍵盤被隱藏)
? ? ? ?// ? ?[tf1 resignFirstResponder];
? ?}