2012-05-23 69 views
5

For example, I want the "test" text a little bit right, what property should I set?縮進的UITextField

UITextView的壓痕問題:

例如,我想「測試」的文字一點點吧,我應該設置的屬性?

+0

點點權利或完全正確? – Ravi

+0

@Ravi有點 –

+0

http://stackoverflow.com/questions/7565645/indent-the-text-in-a-uitextfield – Fattie

回答

8

創建子類並覆蓋textRectForBounds:editingRectForBounds:。你的新的實現可能看起來像

- (CGRect)textRectForBounds:(CGRect)bounds; 
{ 
    return CGRectInset([super textRectForBounds:bounds], 10.f, 0.f); 
} 

- (CGRect)editingRectForBounds:(CGRect)bounds; 
{ 
    return CGRectInset([super editingRectForBounds:bounds], 10.f, 0.f); 
} 
12

試試這個

UIView *paddingView   = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)]; 
    self.yourtextField.leftView    = paddingView; 
    self.yourtextField.leftViewMode   = UITextFieldViewModeAlways; 
+0

這工作沒有子類。最好的方法恕我直言。謝謝。 – rmvz3

+3

偉大的回答,拯救了我的生活! –

+0

我想從頂部縮進什麼編號 –

1

剛剛嘗試像這樣簡單的方法....

textfield.frame = CGRectMake(textfield.frame.origin.x+10, textfield.frame.origin.y, textfield.frame.size.width, textfield.frame.size.height);