2015-04-23 20 views
0

使用兩個TextField或在後臺使用標籤/視圖。將TextField放置在某些視圖/標籤/ TextFields上是不適當的開發。並把標籤或視圖左側是不是我沒想到下面的方法是正確的方法正確的方法要麼如何使UITextField文本輸入在5-6個空格字符後啓動

enter image description here

。所以,我希望有一個更好的解決方案

UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(10,0,7,26)]; 
leftView.backgroundColor = [UIColor clearColor]; 

textField.leftView = leftView; 

textField.leftViewMode = UITextFieldViewModeAlways; 
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 

我們如何使用後,實現它

// placeholder position 
- (CGRect)textRectForBounds:(CGRect)bounds { 
    return CGRectInset(bounds , 10 , 10); 
} 

// text position 
- (CGRect)editingRectForBounds:(CGRect)bounds { 
    return CGRectInset(bounds , 10 , 10); 
} 

我能夠使用來實現。但有那麼一些更好的方法在此的UITextField

Txt_SecurityAns.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0); 
Txt_Email.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0); 
+3

看看[添加插圖中的UITextField(http://stackoverflow.com/questions/2694411/text-inset-for-uitextfield) – Apoorv

+0

如何使用我沒有得到它//佔位符位置 - (CGRect)textRectForBounds:(CGRect)bounds {return} CGRectInset(bounds,10,10); } //文本位置 - (CGRect)editingRectForBounds:(CGRect)bounds {return} CGRectInset(bounds,10,10); } –

回答

1

集paddingView ...

UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0,0,7,26)]; 
textField.leftView = leftView; 
textField.leftViewMode = UITextFieldViewModeAlways; 
+0

我不想添加標籤或視圖等我想使用TextFields的一些編程工作來實現它 –

+0

請參閱此URL:http://stackoverflow.com/questions/2694411/text-inset-for- uitextfield – Rahul

+0

如何使用我沒有得到它//佔位符位置 - (CGRect)textRectForBounds:(CGRect)bounds {return CGRectInset(bounds,10,10); } //文本位置 - (CGRect)editingRectForBounds:(CGRect)bounds {return CGRectInset(bounds,10,10); } –

相關問題