简体   繁体   English

iOS的UITextField的输入范围宽度

[英]Input Range Width Of UITextField iOS

Is it possible to set a UITextField's input range (not the number of characters)? 是否可以设置UITextField的输入范围(而不是字符数)? You can check out my screenshot below. 您可以在下面查看我的屏幕截图。

在此处输入图片说明

I already tried implementing this: Ellipsis at the end of UITextView 我已经尝试实现此方法: UITextView末尾的省略号

It didn't work, or I'm just doing it wrong. 它没有用,或者我只是做错了。

What I want is to limit the size of the user's input AND make it ellipsis. 我想要的是限制用户输入的大小并使其省略号。 The text at the left side of UITextfields are merely UILabels set as subviews. UITextfields左侧的文本只是设置为子视图的UILabel。

So again... I need help in setting the range of the text input, and if the input length or width overlaps my RED MARK in my screenshot, the rest of the input will be converted to POINTS OF ELLIPSIS. 再次,...在设置文本输入的范围时需要帮助,并且如果输入的长度或宽度与我的屏幕截图中的红色标记重叠,则其余输入将被转换为“椭圆点”。 And then I'm pretty sure I can now proceed to my project (example: clicking the arrow button will make a small popup that will show the full text). 然后,我很确定自己现在可以继续进行我的项目了(例如:单击箭头按钮将弹出一个小的对话框,将显示全文)。

I forgot to add my codes in that UITextField: 我忘记将代码添加到该UITextField中:

self.billingAddressTextField = [[UITextField alloc] init];
_billingAddressTextField.frame = CGRectMake(0, 150, scrollView.frame.size.width, 50);
_billingAddressTextField.delegate = self;
_billingAddressTextField.borderStyle = UITextBorderStyleNone;
_billingAddressTextField.background = [UIImage imageNamed:@"textfieldLogIn.png"];
[_billingAddressTextField setTextColor:[UIColor colorWithRed:0.686 green:0.686 blue:0.686 alpha:1.0]];
_billingAddressTextField.backgroundColor = [UIColor clearColor];
_billingAddressTextField.autocapitalizationType = UITextAutocapitalizationTypeWords;
[_billingAddressTextField setFont:[_billingAddressTextField.font fontWithSize:16.0f]];
[_billingAddressTextField setTextAlignment:NSTextAlignmentRight];
[scrollView addSubview:_billingAddressTextField];

Ok solved, I just added a new Padding (UIView) at the left side of the UITextField (billingAddressTextField). 好了,我刚刚在UITextField(billingAddressTextField)的左侧添加了一个新的Padding(UIView)。 So there are now two paddings (both side) in my UITextField. 所以现在我的UITextField中有两个填充(两侧)。

UIView *paddingViewForArrowButton = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 25)];
_billingAddressTextField.rightView = paddingViewForArrowButton;
_billingAddressTextField.rightViewMode = UITextFieldViewModeAlways;

UIView *paddingforBillingLeft = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 25)];
_billingAddressTextField.leftView = paddingforBillingLeft;
_billingAddressTextField.leftViewMode = UITextFieldViewModeAlways;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM