Position of rightView UITextField

前端 未结 3 1096
失恋的感觉
失恋的感觉 2021-01-04 18:21

Is there a way to adjust the position of a rightView on UITextField? I tried setting the frame on the view (set as rightView) but it didn\'t change anything.

I\'d li

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 18:52

    The right overlay view is placed in the rectangle returned by the rightViewRectForBounds: method of the receiver.

    So I suggest you subclass UITextField and override this method, something like this:

    @interface CustomTextField: UITextField
    
    @end
    
    @implementation CustomTextField
    
    // override rightViewRectForBounds method:
    - (CGRect)rightViewRectForBounds:(CGRect)bounds{
        CGRect rightBounds = CGRectMake(bounds.origin.x + 10, 0, 30, 44);
        return rightBounds ;
    }
    

提交回复
热议问题