溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iOS UITextField的基本用法

發布時間:2020-05-24 10:19:32 來源:網絡 閱讀:1237 作者:大頭狼小鬼 欄目:移動開發

 UITextField *textField = [[UITextField alloc] init];//初始化

    textField.userInteractionEnabled = YES;//是否可用

    textField.text = @"UITextField"; //文字

    textField.delegate = self; //代理

    textField.frame = CGRectMake(100, 100, 100, 40); //大小和位置

    textField.textColor = [UIColor redColor];//  字體顏色

    textField.placeholder = @"UITextField";//提示字符

    [textField setBorderStyle:UITextBorderStyleRoundedRect]; //外框類型UITextBorderStyleRoundedRect枚舉類型

    textField.secureTextEntry = YES; //密碼框

    textField.clearButtonMode = UITextFieldViewModeWhileEditing; //編輯時會出現個修改X

    UIImageView *imgv=[[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"right.png"]];

    textField.rightView=imgv;

    textField.rightViewMode = UITextFieldViewModeAlways; //右側加圖片

    textField.font = [UIFont systemFontOfSize:14.0f];//文字的大小

    textField.font = [UIFont boldSystemFontOfSize:14.0f];//文字加粗

    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;  //首字母是否自動大寫


    textField.clearsOnBeginEditing = YES;    //再次編輯就清空


    textField.adjustsFontSizeToFitWidth = YES;  //設置為YES時文本會自動縮小以適應文本窗口大小.默認是保持原來大小,而讓長文本滾動

    textField.minimumFontSize = 20;   //設置自動縮小顯示的最小字體大小

    textField.keyboardType = UIKeyboardTypeNumberPad;   //設置鍵盤的樣式

    textField.backgroundColor = [UIColor grayColor];//背景顏色

    //placeholder 顏色

    //第一種

    UIColor *color = [UIColor whiteColor];

    textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用戶名" attributes:@{NSForegroundColorAttributeName: color}];

    //第二種

    [textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];//_placeholderLabel.textColor這個不可以修改

    textField.returnKeyType =UIReturnKeyDone;   //return鍵變成什么鍵

    //文字上下居中

    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

    //文字左右居中

    textField.textAlignment = NSTextAlignmentCenter;

  textField.keyboardAppearance=UIKeyboardAppearanceDefault;  //鍵盤外觀


    //UITextField左邊的距離

    CGRect frame = [textField frame];

    frame.size.width = 15;

    UIView *leftview = [[UIView alloc] initWithFrame:frame];

    textField.leftViewMode = UITextFieldViewModeAlways;  //左邊距為15pix

    textField.leftView = leftview;

    [textField becomeFirstResponder];//成為第一響應者

    [self.view addSubview:textField];


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女