你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> UITextField根底語法

UITextField根底語法

編輯:IOS開發綜合

這裡講述的是UITextField根底語法的相關引見,詳細代碼請看下文

#pragma mark - 1.創立TextField

- (void)createTextField {

UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, 250, 45)];

textFiled.tag = 1;

[self.view addSubview:textFiled];

}

#pragma mark - 2.設置TextFieldOutLook

- (void)setUpTextFieldOutLook {

UITextField *textField = [self.view viewWithtag:1];

//設置邊框

/*

UITextBorderStyleNone,

UITextBorderStyleLine, 線性邊框

UITextBorderStyleBezel, 斜射邊框

UITextBorderStyleRoundedRect 圓角邊框,顯示不出背景圖片

*/

textField.borderStyle = UITextBorderStyleNone;//在圓角邊框下,顯示不出背景圖片

//設置背景圖片

textField.background = [UIImage imageNamed:@"dove"];

//制止用戶操作 enabled使可以

textField.enabled = NO;//設置為NO點擊就不呼應了

//設置不可操作下的圖片。點擊無用

textField.disabledBackground = [UIImage imageNamed:@"dove2"];

textField.enabled = YES;// 改為Yes 後,可以呼應,但圖片是enabled狀況下的圖片dove.png

}

#pragma mark - 3.設置文本

- (void)setText {

UITextField *textField = [self.view viewWithtag:1];

// 1.根本文本款式設置

textField.placeholder = @"請輸出賬號";

textField.font = [UIFont boldSystemFontOfSize:16];

textField.textColor = [UIColor redColor];

textField.textAlignment = NSTextAlignmentLeft;

// 2.顯示清空按鈕

/*

UITextFieldViewModeNever,

UITextFieldViewModeWhileEditing,

UITextFieldViewModeUnlessEditing,

UITextFieldViewModeAlways

*/

textField.clearButtonMode = UITextFieldViewModeAlways;

//3.設置文字自順應內容的寬度,與最小字體

textField.adjustsFontSizeToFitWidth = YES;

textField.minimumFontSize = 5;

//4.設置右邊,左邊的圖片

UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];

leftImageView.image = [UIImage imageNamed:@"qq"];

textField.leftView = leftImageView;

textField.leftViewMode = UITextFieldViewModeAlways;

UIImageView *rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];

rightImageView.image = [UIImage imageNamed:@"weixin"];

textField.rightView = rightImageView;

textField.rightViewMode = UITextFieldViewModeAlways;

//5.設置密文顯示

//textField.secureTextEntry = YES;

//代碼設置自動獲取焦點,假如不設置就沒有光標顯示,點擊之後才有顯示

[textField becomeFirstResponder];

//6.設置單詞字母能否大寫

/*

UITextAutocapitalizationTypeNone,沒有

UITextAutocapitalizationTypeWords, 每一個單詞首字母大寫

UITextAutocapitalizationTypeSentences, 每一個句子的首字母

UITextAutocapitalizationTypeAllCharacters,每個英文字母都大寫

*/

textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

//7.能否糾錯

/*

UITextAutocorrectionTypeDefault,

UITextAutocorrectionTypeNo,

UITextAutocorrectionTypeYes,

*/

textField.autocorrectionType = UITextAutocorrectionTypeYes;

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

UITextField * textField = (UITextField*)[self.view viewWithtag:1];

//得到焦點

[textField resignFirstResponder];

}

#pragma mark - 4.設置鍵盤

- (void)setkeyboard {

UITextField *textField = [self.view viewWithTag:1];

// 修正鍵盤的顏色

/*

UIKeyboardAppearanceDefault, // Default apperance for the current input method.

UIKeyboardAppearanceDark NS_ENUM_AVAILABLE_IOS(7_0),

UIKeyboardAppearanceLight NS_ENUM_AVAILABLE_IOS(7_0),

UIKeyboardAppearanceAlert = UIKeyboardAppearanceDark, // Deprecated

*/

textField.keyboardAppearance = UIKeyboardAppearanceDefault;

//鍵盤的款式

textField.keyboardType = UIKeyboardTypeDefault;

// 設置inputview和inputAccessoryView

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];

view.backgroundColor = [UIColor brownColor];

textField.inputView = view;

UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];

view1.backgroundColor = [UIColor blueColor];

textField.inputAccessoryView = view1;

}

經過本文的學習希望對您理解和學習IOS開發的相關知識有一些好的協助.感激關注本站.我們將為您搜集更多更好的ios開發教程.

【UITextField根底語法】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved