2012-05-14 45 views
1
textField.layer.backgroundColor = [UIColor lightGreenColorTransparent].CGColor; 
textField.layer.cornerRadius = 8.0f; 
textField.layer.borderColor = [UIColor lightGrayColor].CGColor; 
textField.layer.borderWidth = 1.0f; 

如何將文本設置爲5px右側的文本的邊界和文本開頭之間的空間更大?將文本放在UITextField中

Image

回答

1
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];   
textField.leftView = paddingView; 
textField.leftViewMode = UITextFieldViewModeAlways; 

設置填充所述的UITextField的leftView屬性。

1

drawTextInRect: 繪製在指定的矩形與接收器的文本。

- (void)drawTextInRect:(CGRect)rect 

參數 RECT 在其中繪製文本的矩形。 討論 您不應該直接調用此方法。如果要爲文本自定義繪圖行爲,可以覆蓋此方法來執行繪圖。

在調用此方法時,當前圖形上下文已經使用默認環境和文本顏色進行了繪製。在您重寫的方法中,您可以進一步配置當前上下文,然後調用super來執行實際繪圖,或者您可以自己完成繪圖。如果你自己渲染文本,你不應該調用super。

可用性 適用於iOS 2.0及更高版本。 宣佈 UITextField.h

1
textField.contentInset = UIEdgeInsetsMake(4,8,0,0); 
+0

不起作用。 Xcode沒有找到這個方法。你是不是指「內容模式」? – DAS

+0

您正在使用的Xcode版本 –

+0

Xcode 4.2 ..... – DAS