日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UITextField的属性与程序启动后一系列方法

發(fā)布時間:2025/4/16 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UITextField的属性与程序启动后一系列方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

// UITextField 文本輸入框

? ? // UITextField 繼承與 UIControl

? ? // UIContr 繼承與 UIView

?? self.textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];

? ? self.textField.backgroundColor = KMyColor;

?? // 設(shè)置代理

? ? self.textField.delegate = self;

?? ?

?? // 設(shè)置占位符

? ? self.textField.placeholder = @"請輸入";

? ?

?? // 字體大小

? ? self.textField.font = [UIFont systemFontOfSize:25];

? ?

? ? // 字體顏色

? ? self.textField.textColor = [UIColor redColor];

?? ?

?? // 對齊方式

?? self.textField.textAlignment = NSTextAlignmentLeft;

?? ?

?? // 是否允許輸入 也就是是否開啟交互 默認是YES 支持交互

? ? // textField.enabled = YES;

? ? // 任何一個有交互行為的控件 交互默認都是打開的 但是我們也可以將其關(guān)閉

? ? //self.textField.userInteractionEnabled = YES;

?? ?

? ? // 輸入的時候 為密碼模式(安全輸入模式)

? ? //self.textField.secureTextEntry = YES;

?? ?

? ? // 下一次輸入的時候 是否清空上一次的內(nèi)容

?? //self.textField.clearsOnBeginEditing = YES;

?? ?

? ? // 設(shè)置return鍵的樣式 默認是換行

? ? //self.textField.returnKeyType = UIReturnKeySearch;

?? ?

? ? // 設(shè)置鍵盤樣式 默認的是英文

? ? //self.textField.keyboardType = UIKeyboardTypeNumberPad;

?? ?

? ? // 是否顯示 清除按鈕 默認是不顯示

? ? self.textField.clearButtonMode = UITextFieldViewModeAlways;

?? ?

? ? // textField 添加左視圖 和右視圖

? ?

? ? // 自定義左邊視圖

? ? /*

? ? UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];

?? leftView.backgroundColor = [UIColor greenColor];

? ? self.textField.leftView = leftView;

? ? self.textField.leftViewMode = UITextFieldViewModeAlways;

? ? [leftView release];

? ? // 自定義右邊視圖

? ? UIView *rightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];

? ? rightView.backgroundColor = [UIColor redColor];

? ? self.textField.rightView = rightView;

? ? self.textField.rightViewMode = UITextFieldViewModeAlways;

? ? [rightView release];

?? ? */

? ? // textField 設(shè)置邊框圓角 常用的樣式 因為比較好看

? ? self.textField.borderStyle = UITextBorderStyleRoundedRect;

?? ?

? ? // 自定義鍵盤

?? /*

? ? UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];

? ? view.backgroundColor = [UIColor redColor];

? ? self.textField.inputView = view;

? ? [view release];

? ? */ ? ?

? ? // 自定義鍵盤上面的視圖

? ? /*

? ? UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];

? ? view.backgroundColor = [UIColor redColor];

?? self.textField.inputAccessoryView = view;

? ? [view release];

? ? */

?? ?

? ? // 等號左邊的是set方法 要用self. 等號右邊的是 get方法 要用_

? ? [self.window addSubview:_textField];

? ? [self.textField release];

?? ?

?? ?

// UIButton 按鈕

? ? // UIButton 繼承與 UIControl

? ? // UIControl 繼承與 UIView

? ? // button 類方法創(chuàng)造出來 切記 不需要釋放

? ? // button 添加背景圖片 圖片的寬高 需要和button的寬高結(jié)合起來使用 button的寬高 = 圖片的寬高 / 2

? ? // 背景圖片 button的類型必須是 UIButtonTypeSystem

? ? // 前景圖片 button的類型必須是 UIButtonTypeCustom

? ? //UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

? ? UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

? ? button.frame = CGRectMake(100, 200, 290 / 2 , 92 / 2);

?? ?

?? // button.backgroundColor = [UIColor redColor];

? ? // 設(shè)置button標(biāo)題

? ? [button setTitle:@"按鈕" forState:UIControlStateNormal];

? ? button.tag = 100;

?

? ? // 設(shè)置標(biāo)題顏色

? ? [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

? ? // 取出button標(biāo)題

? ? NSString *titleString = [button titleForState:UIControlStateNormal];

? ? NSLog(@"%@",titleString);

? ? [self.window addSubview:button];

?? ?

?? ?

? ? UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];

? ? button2.frame = CGRectMake(100, 300, 290 / 2, 92 / 2);

? ? [button2 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];

? ? [button2 setTitle:@"按鈕2" forState:UIControlStateNormal];

? ? [self.window addSubview:button2];

? ? button2.tag = 200;

?? ?

?? ?

? ? // button 添加點擊事件

? ? //[button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchDown];//點進去觸發(fā)

? ? // 點下去松開才會觸發(fā)

? ? [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

?

? ? [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

??

?? ?

? ? // button設(shè)置背景圖片

? ? // UIImage 繼承與 NSObject 他不是一個控件

? ? // UIImage 需要通過 某一個控件 才能夠展示出來

? ? /*

? ? [button setBackgroundImage:[UIImage imageNamed:@"denglu.png"] forState:UIControlStateNormal];

? ? // 取出button的背景圖片

? ? UIImage *image = [button backgroundImageForState:UIControlStateNormal];

? ? [button setBackgroundImage:image forState:UIControlStateNormal];

?? ? */

?? ?

//? ? // button設(shè)置前景圖片

//? ? [button setImage:[UIImage imageNamed:@"denglu.png"] forState:UIControlStateNormal];

//? ? [self.window addSubview:button];

// ? ?

//? ? [button2 setImage:[UIImage imageNamed:@"zhuce.png"] forState:UIControlStateNormal];

//? ? [self.window addSubview:button2];

//? ? //button.clipsToBounds = YES;

//? ? //button.layer.masksToBounds = YES;

// ? ?

//? ? // button取出前景圖片

//? ? UIImage *image = [button imageForState:UIControlStateNormal];

//? ? [button setImage:image forState:UIControlStateNormal];

?? ?

? ? return YES;

}

?

?

#pragma mark --- alertView代理方法------

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

? ? if (alertView.tag == 300)

? ? {

? ? ? ? if (buttonIndex == 0)

? ? ? ? {

? ? ? ? ? ? NSLog(@"點擊了取消");

? ? ? ? }

? ? ? ? else if(buttonIndex == 1)

? ? ? ? {

? ? ? ? ? ? NSLog(@"點擊了確定");

? ? ? ? }

? ? ? ? else if(buttonIndex == 2)

? ? ? ? {

? ? ? ? ? ? NSLog(@"點擊了哈哈");

? ? ? ? }

? ? }

? ? else if (alertView.tag == 400)

? ? {

? ? ? ? if (buttonIndex == 0)

? ? ? ? {

? ? ? ? ? ? NSLog(@"點擊了注冊的取消");

? ? ? ? }

? ? ? ? else if(buttonIndex == 1)

? ? ? ? {

? ? ? ? ? ? NSLog(@"點擊了注冊的確定");

? ? ? ? }

? ? ? ? else if(buttonIndex == 2)

? ? ? ? {

? ? ? ? ? ? NSLog(@"點擊了注冊的哈哈");

? ? ? ? }

?

? ? }

}

?

// 這個代理方法 只是找到點擊鍵盤的return

// 內(nèi)部具體要實現(xiàn)什么樣的效果 取決于代碼

// 我們此時只是實現(xiàn)了 點擊return 回收鍵盤

/*

- (void)buttonAction

{

? ? NSLog(@"正在錄音");

? ? //self.window.backgroundColor = [UIColor redColor];

}

*/

- (void)buttonAction:(UIButton *)button

{

? ? if (button.tag == 100)

? ? {

? ? ? ? // 設(shè)置了代理之后 delegate后面要跟 self

? ? ? ? UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"是否登錄" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定",@"哈哈", nil];

? ? ? ? alertView.tag = 300;

? ? ? ? // 設(shè)置樣式

? ? ? ? alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

? ? ? ? // 取到提示框上的textField

? ? ? ? /*

? ? ? ? UITextField *textField = [alertView textFieldAtIndex:0];

? ? ? ? textField.backgroundColor = [UIColor orangeColor];

? ? ? ? */

?? ? ? ?

? ? ? ? // 消息機制 幾秒之后 self 去執(zhí)行alertViewDismiss這個方法 傳入的參數(shù)是alertView

? ? ? ? //[self performSelector:@selector(alertViewDismiss:) withObject:alertView afterDelay:3];

?? ? ? ?

? ? ? ? // alertView展示出來

? ? ? ? // alertView層級 是最高的 不需要刻意添加

? ? ? ? [alertView show];

? ? ? ? [alertView release];

? ? ? ? //NSLog(@"button1");

? ? }

? ? else if (button.tag == 200)

? ? {

? ? ? ? UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"是否登錄" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定",@"哈哈", nil];

? ? ? ? alertView.tag = 400;

? ? ? ? [alertView show];

? ? ? ? [alertView release];

? ? ? ? // NSLog(@"button2");

? ? }

? ? //NSLog(@"發(fā)送消息");

? ? //self.window.backgroundColor = [UIColor greenColor];

?

}

#pragma mark --- alertView消失---

- (void)alertViewDismiss:(UIAlertView *)alertView

{

? ? [alertView dismissWithClickedButtonIndex:0 animated:YES];

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

? ? // 取消第一響應(yīng)者

? ? [self.textField resignFirstResponder];

? ? return YES;

}

#pragma mark --- 點擊空白處回收鍵盤 ---

點擊空白處 回收鍵盤

//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

//{

//? ? //self.textField = self.window.subviews[0];

//? ? [self.textField resignFirstResponder];

//}

?

程序啟動步驟

- (void)applicationWillResignActive:(UIApplication *)application

{

?? // NSLog(@"將要進入到非活躍狀態(tài) 就是將要進入到后臺");

?

}

?

- (void)applicationDidEnterBackground:(UIApplication *)applicatio

{

?? // NSLog(@"已經(jīng)進入到非活躍狀態(tài) 就是已經(jīng)進入到后臺");

?

}

?

- (void)applicationWillEnterForeground:(UIApplication *)application

{

?? // NSLog(@"將要進入到活躍狀態(tài) 就是將要進入到前臺");

?

}

?

- (void)applicationDidBecomeActive:(UIApplication *)application

{

?? // NSLog(@"已經(jīng)進入到活躍狀態(tài) 已經(jīng)進入到前臺");

?

}

?

- (void)applicationWillTerminate:(UIApplication *)application

{

?? // NSLog(@"將要退出應(yīng)用程序 就是滑飛");

?

}

?

轉(zhuǎn)載于:https://www.cnblogs.com/star001/p/5211160.html

總結(jié)

以上是生活随笔為你收集整理的UITextField的属性与程序启动后一系列方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。