本文介绍了rightView UITextField 的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 UITextField 上调整 rightView 的位置?我尝试在视图上设置框架(设置为 rightView),但没有任何改变.

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.

我想避免制作两个视图,一个作为 rightView,一个作为 rightView 的子视图,如果可能的话,我会在其中更改子视图的位置.

I'd like to avoid making two views, one as the rightView and one as the rightView's subview where I change the subview's position, if possible.

推荐答案

右叠加视图放置在接收方的rightViewRectForBounds:方法返回的矩形中.

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

所以我建议你继承 UITextField 并覆盖这个方法,像这样:

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 ;
}

这篇关于rightView UITextField 的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 02:36