当前位置:首页 > 操作系统 > Ios

(iOS)修改UITextField高度

修改UITextField高度

===

---

## 是否可以通过修改frame改变高度

网上流传的代码中使用如下一份代码:

//    以下代码任然不能改变UITextField高度

        CGRect rect = _userNameField.bounds;

        rect.size.height = 88;

        rect.size.width = 20;

        _userNameField.bounds = rect;

   

所以不可以。

---

## 通过自定义子类实现修改UITextField高度

  在子类中覆盖``- (CGRect)borderRectForBounds:(CGRect)bounds``方法,即可

  

         /**

         *  通过以下代码实现设置文本框高度

         *  44是所希望的高度

         */

        - (CGRect)borderRectForBounds:(CGRect)bounds

        {

            bounds.size.height = 44;

            return bounds;

        }

>### Parameters

>* bounds

>

>The bounding rectangle of the receiver.

>

>* Return Value

>

>The border rectangle for the receiver.


原文:http://my.oschina.net/agony/blog/387322


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!