zoukankan      html  css  js  c++  java
  • TextField的文字距左边框的距离偏移

    默认情况下,当向textField输入文字时,文字会紧贴在textField左边框上.

    我们可以通过设置textField的leftView,设置一个只有宽度的leftView.

    这样还不够,因为默认leftView是不显示的.还需要将leftViewMode设置为 UITextFieldViewModeAlways.这样就完成了.


    (小技巧:通过查询UITextField的头文件可以看出leftView和leftViewMode这两个属性写在了一组,与其他属性之间是分开的,说明这两个属性的关系很紧密)

     UITextField *textField = [[UITextField alloc]init];
        textField.frame = CGRectMake(10, 30, 300, 30);
        textField.placeholder = @"测试";
        textField.borderStyle = UITextBorderStyleLine;
        [self.view addSubview:textField];


        textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 0)];
        //设置显示模式为永远显示(默认不显示)
        textField.leftViewMode = UITextFieldViewModeAlways;

  • 相关阅读:
    第八章 多线程编程
    Linked List Cycle II
    Swap Nodes in Pairs
    Container With Most Water
    Best Time to Buy and Sell Stock III
    Best Time to Buy and Sell Stock II
    Linked List Cycle
    4Sum
    3Sum
    Integer to Roman
  • 原文地址:https://www.cnblogs.com/jone-liu/p/4971725.html
Copyright © 2011-2022 走看看