2012-05-23 24 views
5

For example, I want the "test" text a little bit right, what property should I set?lõm trong UITextField

UITextView vấn đề thụt đầu dòng:

Ví dụ, tôi muốn "test" văn bản một chút đúng, những gì bất động sản tôi nên thiết lập?

+0

Little bit đúng hay hoàn toàn đúng? – Ravi

+0

@Ravi chút bit –

+0

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

Trả lời

8

Tạo lớp con và ghi đè textRectForBounds:editingRectForBounds:. triển khai mới của bạn có thể trông giống như

- (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

Hãy thử điều này

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

Tác phẩm này không có phân lớp phụ. IMHO phương pháp tốt nhất. Cảm ơn. – rmvz3

+3

Câu trả lời hay, cứu mạng tôi! –

+0

Id nào tôi muốn thụt lề từ đầu –

1

Chỉ cần cố gắng như phương pháp đơn giản này ....

textfield.frame = CGRectMake(textfield.frame.origin.x+10, textfield.frame.origin.y, textfield.frame.size.width, textfield.frame.size.height); 
Các vấn đề liên quan