2015-10-29 104 views
0

是否可以设置UITextField的输入范围(不是字符数)?你可以看看下面的截图。UITextField的输入范围宽度iOS

enter image description here

我已经尝试实现这个:Ellipsis at the end of UITextView

它没有工作,或者我只是做是错误的。

我想是限制用户输入的大小,使其省略号。 UITextfields左侧的文本仅仅是UILabels设置为子视图。

因此,我需要帮助来设置文本输入的范围,并且如果输入的长度或宽度与我的屏幕截图中的RED MARK重叠,则其余输入将转换为ELLIPSIS的点。然后,我很确定我现在可以继续到我的项目(例如:单击箭头按钮将使一个小的弹出窗口显示全文)。

我忘了加在我的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]; 

回答

0

好解决,我只是在的UITextField(billingAddressTextField)的左侧添加了一个新的填充(的UIView)。所以现在我的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;