zoukankan      html  css  js  c++  java
  • iOS-textfield控制光标开始位置

    //    UIView *paddingView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
    //    paddingView1.backgroundColor = [UIColor lightGrayColor];
    //    self.phoneTextField .leftView = paddingView1;
    //    self.phoneTextField.leftViewMode = UITextFieldViewModeAlways;
    //    [self.view addSubview:paddingView1];
    //    
    //    self.phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 0, self.view.frame.size.width,textFieldH )];
    //    self.phoneTextField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"手机" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    //    self.phoneTextField.delegate = self;
    //    self.phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    //    self.phoneTextField.returnKeyType = UIReturnKeyDone;
    //    [paddingView1 addSubview:self.phoneTextField];

    这是第一种办法,就是添加leftview

    第二种就是自定义UItextField

    #import <UIKit/UIKit.h>

    @interface textField : UITextField

    //控制 placeHolder 的位置,左右缩 10
    - (CGRect)textRectForBounds:(CGRect)bounds;

    // 控制文本的位置,左右缩 10
    - (CGRect)editingRectForBounds:(CGRect)bounds;
    @end
    textField.m

    #import "textField.h"

    @implementation textField

    - (CGRect)textRectForBounds:(CGRect)bounds {
        return CGRectInset( bounds , 10*1 , 0 );
    }

    // 控制文本的位置,左
    - (CGRect)editingRectForBounds:(CGRect)bounds {
        return CGRectInset( bounds , 10*1 , 0 );
    }
    @end

  • 相关阅读:
    嵌入式Linux操作系统学习规划
    底层机器指令学习
    汇编学习笔记
    无符号和有符号数操作优先级
    栈和堆的区别
    图Graph
    判断单链表里面有没有环
    centos配置中文显示和中文输入
    数组相关问题求解
    KMP算法
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5535287.html
Copyright © 2011-2022 走看看