UITextField,uitextfield多行

來源:互聯網
上載者:User

UITextField,uitextfield多行

//1、    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30, 100, 260, 40)];    //2、//    textField.backgroundColor = [UIColor redColor];        //屬性    //設定文字顏色:textColor    textField.textColor = [UIColor redColor];    //邊框狀態:borderStyle    /*     1、UITextBorderStyleRoundedRect   圓角     2、UITextBorderStyleLine          黑色直角邊框     3、UITextBorderStyleBezel         灰色直角邊框     4、UITextBorderStyleNone          無邊框     */    textField.borderStyle = UITextBorderStyleRoundedRect;    //文字水平對齊:textAlignment   預設靠左對齊    textField.textAlignment = NSTextAlignmentLeft;    //文字垂直對齊:contentVerticalAlignment    預設置中    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    //設定字型大小:font    textField.font = [UIFont systemFontOfSize:20.0];    //自適應文字大小:adjustsFontSizeToFitWidth    textField.adjustsFontSizeToFitWidth = YES;    //設定最小字型大小:minimumFontSize    textField.minimumFontSize = 20.0;    //預設文字:text    textField.text = @"hello world”;    //提示文字:placeholder    textField.placeholder = @"請輸入帳號";    //密文:secureTextEntry    textField.secureTextEntry = NO;    //輸入框是否可用:enabled    textField.enabled = YES;    //return鍵的類型:returnKeyType    /*     1、UIReturnKeyDefault         return     2、UIReturnKeyDone            Done     3、UIReturnKeyEmergencyCall   EmergencyCall     4、UIReturnKeyGoogle=UIReturnKeyYahoo=UIReturnKeySearch   Search     5、UIReturnKeyJoin   Join     .     .     .     */    textField.returnKeyType = UIReturnKeyJoin;    //鍵盤類型:keyboardType    /*     1、UIKeyboardTypeDefault   數字,符號,中英文     2、UIKeyboardTypeNumberPad   數字鍵台     3、UIKeyboardTypeWebSearch  網址  .     4、UIKeyboardTypeURL     .com  /   .     5、UIKeyboardTypeEmailAddress   @  .     6、UIKeyboardTypeNumbersAndPunctuation   數字 符號     .     .     .     */    textField.keyboardType = UIKeyboardTypeDefault;    //鍵盤顏色:keyboardAppearance    /*     1、UIKeyboardAppearanceDefault=UIKeyboardAppearanceLight  淺灰色     2、UIKeyboardAppearanceAlert=UIKeyboardAppearanceDark   深灰色     */    textField.keyboardAppearance = UIKeyboardAppearanceDefault;    //背景圖片:background    當邊框狀態為圓角時,背景圖片無效    textField.background = [UIImage imageNamed:@"map.png"];    //一鍵清除按鈕:clearButtonMode    /*     1、UITextFieldViewModeAlways         一直出現     2、UITextFieldViewModeNever          永不出現     3、UITextFieldViewModeWhileEditing   輸入框編輯文字時出現,不編輯時消失     4、UITextFieldViewModeUnlessEditing  輸入框編輯文字時消失,不編輯時出現     */    textField.clearButtonMode = UITextFieldViewModeUnlessEditing;    //再次編輯是否清空之前的文字:clearsOnBeginEditing   YES:清空    textField.clearsOnBeginEditing = YES;    //是否自動大寫:autocapitalizationType    /*     1、UITextAutocapitalizationTypeAllCharacters   所有字母都大寫     2、UITextAutocapitalizationTypeNone    所有字母都不大寫     3、UITextAutocapitalizationTypeSentences   每個句子的首字母大寫     4、UITextAutocapitalizationTypeWords   每個單詞的首字母大寫     */    textField.autocapitalizationType = UITextAutocapitalizationTypeWords;    //是否自動錯誤修正:autocorrectionType    /*     1、UITextAutocorrectionTypeDefault   預設     2、UITextAutocorrectionTypeNo   不錯誤修正     3、UITextAutocorrectionTypeYes   錯誤修正     */    textField.autocorrectionType = UITextAutocorrectionTypeYes;    //設定左視圖:leftView    //設定位置無效    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];    view.backgroundColor = [UIColor redColor];    textField.leftView = view;    //左視圖出現狀態:leftViewMode    textField.leftViewMode = UITextFieldViewModeAlways;    //設定右視圖:rightView    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];    view2.backgroundColor = [UIColor yellowColor];//    textField.rightView = view2;    //右視圖出現狀態:rightViewMode//    textField.rightViewMode = UITextFieldViewModeAlways;        //不同的位置,不能用相同的view        //鍵盤上面的view:inputAccessoryView    UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];    view3.backgroundColor = [UIColor purpleColor];    textField.inputAccessoryView = view3;        //擷取輸入框裡面的文字:textField.text    NSString *str = textField.text;    NSLog(@"%@",str);        /**************!!!!!!delegate!!!!!!!*************/    textField.delegate = self;        [textField becomeFirstResponder];        //3、    [self.view addSubview:textField];#pragma mark - UITextFieldDelegate//return鍵的方法  *****- (BOOL)textFieldShouldReturn:(UITextField *)textField{    //輸入框失去響應:鍵盤收回,游標消失    [textField resignFirstResponder];        //輸入框開始響應:鍵盤出現,游標出現//    [textField becomeFirstResponder];        return YES;}//一鍵刪除按鈕的方法- (BOOL)textFieldShouldClear:(UITextField *)textField{    //返回YES:一鍵刪除有效   返回NO:一鍵刪除無效        if ([textField.text isEqualToString:@"123"]) {        return NO;    }    return YES;}//輸入框是否可以開始編輯- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    return YES;}//輸入框是否可以結束編輯   **- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{    if (textField.text.length < 11) {        return NO;    }    return YES;}//輸入框開始響應就調用的方法   ****- (void)textFieldDidBeginEditing:(UITextField *)textField{    NSLog(@"textFieldDidBeginEditing");}//輸入框結束響應就調用的方法   ****- (void)textFieldDidEndEditing:(UITextField *)textField{    NSLog(@"textFieldDidEndEditing");}//頁面跳轉    //第一個參數:即將跳轉的頁面    //第二個參數:帶不帶動畫效果    //第三個參數:跳轉結束後所做的操作        //執行個體化第二個頁面    SecondViewController *second = [[SecondViewController alloc] init];    //跳轉的操作:從下向上出現    [self presentViewController:second animated:YES completion:^{        //        NSLog(@"second");    }];    //返回上一頁:從上向下消失    [self dismissViewControllerAnimated:YES completion:^{        //    }];//頁面生命週期//頁面即將出現- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    NSLog(@"1");}//頁面已經出現- (void)viewDidAppear:(BOOL)animated{    [super viewDidAppear:animated];    NSLog(@"2");}//頁面即將消失- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    NSLog(@"3");}//頁面已經消失- (void)viewDidDisappear:(BOOL)animated{    [super viewDidDisappear:animated];    NSLog(@"4");}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.