年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4928|回复: 0

UITextField调整内容位置及左右视图LeftView、RightView

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2014-8-9 23:23:20 | 显示全部楼层 |阅读模式

    // 清除按钮左移一个单元
    - (CGRect)clearButtonRectForBounds:(CGRect)bounds
    {
        CGRect rect = [super clearButtonRectForBounds:bounds];
        if (_isReservedRightView){
            rect = CGRectOffset(rect, -rect.size.width, 0);
        }
        return rect;
    }

    // 控制 placeHolder 的位置,左右缩 10
    - (CGRect)textRectForBounds:(CGRect)bounds
    {
        CGRect rect = [super textRectForBounds:bounds];
        return CGRectInset(rect, 8, 0);
    }

    // 控制文本的位置,左右缩 10
    - (CGRect)editingRectForBounds:(CGRect)bounds
    {
        CGRect rect = [super textRectForBounds:bounds];
        return CGRectInset(rect, 8, 0);
    }

    // 重写方法,固定viewMode为Always
    - (void)setLeftView:(UIView *)leftView
    {
        [super setLeftView:leftView];
        self.leftViewMode = UITextFieldViewModeAlways;
    }

    注意:clearButton即rightView,如果设置了rightView,clearButton就不会再出现!

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-5-1 06:10 , Processed in 0.048805 second(s), 22 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表