我试图在右边设置边距,UItextfield
但是我无法获得成功。
我尝试下面的代码:
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(1, 1, 60, 25) ];
[lbl setText:@"Partenza:"];
[lbl setFont:[UIFont fontWithName:@"Verdana" size:12]];
[lbl setTextColor:[UIColor grayColor]];
[lbl setTextAlignment:UITextAlignmentLeft];
txtFCarat.rightView = lbl;
txtFCarat.rightViewMode = UITextFieldViewModeAlways;
txtFCarat.delegate = self;
如果有人对此有解决方案,请帮助我!
您可以通过以下两种方法覆盖此方法
@implementation rightTextField
// placeholder position
- (CGRect)textRectForBounds:(CGRect)bounds {
return CGRectInset( self.bounds , margin position , margin position );
}
// text position
- (CGRect)editingRectForBounds:(CGRect)bounds {
return CGRectInset( self.bounds , margin position ,margin position );
}
编辑:用于绑定类似的代码
textField.bounds = [self editingRectForBounds:textField.bounds];
textField.bounds = [self textRectForBounds:textField.bounds];
您的预期答案:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
textfield.rightView = imageView;
textfield.rightViewMode = UITextFieldViewModeAlways;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句