rightView UITextField的位置 [英] Position of 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的子视图,我更改子视图的位置。
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的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!