(iOS)修改UITextField高度

时间:2015-03-15 23:48:15   收藏:0   阅读:1453

修改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.


评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!