UITextField設定正文縮排

Dean發表於2014-11-03
    // 設定文字豎直居中
        loginTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

        // 新增圖示

// 設定iconV作為textfield.leftview使輸入位置後置縮排
        UIImage *icon = [UIImage imageWithName:iconImageName];
// 在iconV上面新增iconIV 使圖片可設定尺寸置中美觀
        UIView *iconV = [[UIView alloc] init];
        UIImageView *iconIV = [[UIImageView alloc] initWithImage:icon];

        // 使文字在icon之前30px輸入
        iconV.width = 59;
        iconV.height = 53.5;
        iconV.backgroundColor = [UIColor clearColor];
        iconIV.frame = CGRectMake(9, 15, 38, 30);


        [iconV addSubview:iconIV];
        loginTextField.leftView = iconV;

        // 設定icon不拉伸
        iconV.contentMode = UIViewContentModeScaleAspectFit;
        iconIV.contentMode = UIViewContentModeScaleAspectFit;

        // leftView的顯示由leftViewMode來確定
        loginTextField.leftViewMode = UITextFieldViewModeAlways;

相關文章