2012-05-23 18 views
5

For example, I want the "test" text a little bit right, what property should I set?Rientro in UITextField

UITextView problema rientro:

Ad esempio, voglio il testo "test" un po 'a destra, quale proprietà dovrei impostare?

+0

Un po 'a destra o completamente a destra? – Ravi

+0

@Ravi little bit –

+0

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

risposta

8

Creare una sottoclasse e sovrascrivere textRectForBounds: e editingRectForBounds:. I tuoi nuovi implementazioni possono essere simile

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

Prova questa

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

Funziona senza sottoclassi. Il miglior metodo IMHO. Grazie. – rmvz3

+3

Ottima risposta, mi ha salvato la vita! –

+0

Quale ID voglio rientrare dall'alto –

1

Basta provare come questo metodo semplice ....

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