UIView

準備工作

1.刪除main

2.ARC -> MRC

3.刪除文件(ViewController.h/.m)

4.storng -> retian(APPDlelgate.h)

5.重寫dealloc(APPDelegate.m)


// ?AppDelegate.m

// ?UI01_UIView

//

// ?Created by dllo on 16/1/20.

// ?Copyright ? 2016年dllo. All rights reserved.

//

#import"AppDelegate.h"

@interfaceAppDelegate ()

@end

@implementationAppDelegate

/********重寫dealloc******/

-(void)dealloc{

[_window release];

[super dealloc];

}

是一個類UIWindow

創(chuàng)建window和當前屏幕一樣大[UIScreen mainSrceen].buond];

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

設置window顏色

self.window.backgroundColor= [ UIClolor whiteColor];

設置window可見

self.window makeKeyAndVisible];

xcode7崩潰解決

self.window.rootViewController = [[UIViewController alloc] init];

內(nèi)存管理

—window release];

UIview(視圖基類)

視圖就是屏幕上的一塊矩形區(qū)域

1.創(chuàng)建視圖 設置Frame

UIView *firstView = [[UIView alloc]initWithFrame :CGRTectMake(0, 0 ,100,100)100款 100 高

2.設置屬性

firstView.backbroundColor = 【UIColor redColor];

添加到父視圖(window)顯示

[self.window addSubview:firstView];

內(nèi)存管理

fristView release];

中心顯示

數(shù)值設置(絕對坐標)

firstView.center = CGPointMake(375/2,667/2);

通過其他控件的位置設置(相對坐標)

firstView.center = self.window.center;

改變frame

firstView.frame = CGRectMake(200,100,100,200);

View的屬性

顯示或隱藏(如果父視圖隱藏了,那么子視圖也同時隱藏)

firstView.hidden = NO;

透明度(0 - 1的浮點數(shù))

firstView.alpha = NO;

子視圖會根據(jù)父視圖的透明度的改變同時發(fā)生改變

子視圖自身的hidden和alpha 值影響自己

父視圖的hidden和alpha影響自身和所有子視圖

tag值(從1000 開始)

firstView.tag =1000;

通過標記尋找視圖(通過Tag值間接改變firstView的顏色)

UIView ?*tempView = [self.window viewWithTag:1000];

tempView..backgroundColor = [UIColor PurpleColor];

父有圖(一個視圖只有一個父視圖)

子視圖(一個子視圖可以有若干個子視圖)

視圖從父視圖移除(就徹底沒了)

把子視圖送到最后

self.window sendSubviewToBack:firstView];

定時器NSTimer

每隔一段時間讓xx做某事

參數(shù)1.時間間隔

參數(shù)2.某事

參數(shù)3.某事

[NSTimer scheduledTimerWithTimerInterval:1 target:self @selector(suibain) userInfo:nil tepeats :YES];

UILable

創(chuàng)建 frame

UILabie *lable = [[UILable alloc】 initWithFrame:CGRectMake(100,100,200,100)];

屬性設置

lable.backgroundColor = [UIColor yellowColor];

添加父視圖

[self.window addSubview:lable];

內(nèi)存管理

[lable release];

/********lable文字相關屬性**********/

顯示漢字(默認左對齊、居中對齊、文本黑色,行數(shù)為1 ,背景為透明色)

lable.textColor = [UIColor redColor];

文本對齊方式

lable.textAlignment = NSTextAlignmentCenter;

文本行數(shù)

默認為1 為0時行數(shù)不限

lable.numerOfLine = 0;

lable自適應(有缺陷)放在文本之后

如果文本不足一行 寬高一起改變

如果 文本超一行 值改變高

一定要寫在設置text之后,如果寫在之前l(fā)able的size會置為0;

字體font

lable.font = UIFont systemFontOfSize:20];

陰影shadow

lable.shadowColor = [UIColor bllueColor];

陰影偏移量

lable.shadowOffset = CGSizeMake(1,5);

UITextField 輸入框

UITextField *tf = [UITextField alloc]initWithFrame:CGRectMake(100,100,100,100)];

tf.backgroundColor = [UIColor cyanColor];

[self.window addSubview:tf];

[tf release];

文本控制******/

占位字符串placeholder(提示信息)

tf.placeholder = YES;

輸入控制

tf.enable = YES;

安全文本類型

tf.secureTextEntry ?= YES;

鍵盤樣式

tf.keyboardType = UIKeyboardDefault;

tf.

外觀控制

輸入框樣式

tf.boardStyle = UITextboardStyleNone;

加邊框?qū)挾?/p>

tf.layer.boardWidth = 1;

邊框顏色

tf,layer.boardColor = 【UIColor lightGrayColor].CGColor;

切圓角(圓形;是正方形邊長的一半)

tf.layer.cornerRAdius = tf.frame.size.width / 2;

清除按鈕

tf.clearButtonMode = UITextFieldModeAlways;

UIButton ?按鈕

UIButton *btn = [UIButton buttonWithTypeSystem];

btn.frame = CGRectMake(100,100,100,,100);

btn.backgroundColor = [UIColor redColor];

綁定按鈕點擊事件(按鈕點擊時 能夠觸發(fā)一個方法)

參數(shù)1:目標(調(diào)用方法的人)

參數(shù)2:動作(調(diào)用的方法)

參數(shù)3:事件(方法的觸動方法)

btn addTarget:self action:@selector(click:)forControllorEvents:UIControlEventTouchUpInside】;

self.window addSubview:btn];

按鈕文字

參數(shù)1:標題內(nèi)容

參數(shù)2:狀態(tài)

[btn setTitle:@"正常" forState:UIControlStateNormal];

[btn setTitle:@"常量" forState:UIControlStateHightlighted];

按鈕顯示觸摸時高亮

[btn.showsTouchWhenHightlighted = YES;

添加事件的方法(注意書寫位置)

鍵盤回收

第一步:簽訂系統(tǒng)協(xié)議

第二步:設定代理人

第三步:協(xié)議方法


/***************只有最后一個鍵盤回收*****************/

每個輸入框都要設置tag值

if(textField.tag==1000) {

第一個輸入框失去第一響應者(失焦:失去焦點)

[textFieldresignFirstResponder];

獲取第二個輸入框

[[self.windowviewWithTag:2000]becomeFirstResponder];

}

if(textField.tag==2000) {

[textFieldresignFirstResponder];

}

returnYES;

}

將要開始輸入時讓屏幕上移露出輸入框

-(BOOL)textFieldShouldBeginEditing:(UITextField*)textField{

if(textField.tag==2000) {

[UIViewanimateWithDuration:0.53animations:^{

self.window.center=CGPointMake(self.window.center.x,self.window.center.y-258);

}];

}

returnYES;

}

將要結束時讓屏幕下移

-(BOOL)textFieldShouldEndEditing:(UITextField*)textField{

if(textField.tag==2000) {

[UIViewanimateWithDuration:0.53animations:^{

self.window.center=CGPointMake(self.window.center.x,self.window.center.y+258);

}];

}

returnYES;

}

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容