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