2012-05-23 17 views
5

For example, I want the "test" text a little bit right, what property should I set?sangría en UITextField

UITextView problema de sangrado:

Por ejemplo, quiero que el texto "prueba" un poco a la derecha, lo que la propiedad debería establecer?

+0

derecho Un poco o totalmente correcto? – Ravi

+0

@Ravi poco –

+0

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

Respuesta

8

Crea una subclase y anula textRectForBounds: y editingRectForBounds:. Sus nuevas implementaciones pueden ser algo como

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

Prueba este

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

Esto funciona sin subclases. El mejor método en mi humilde opinión. Gracias. – rmvz3

+3

¡Gran respuesta, salvó mi vida! –

+0

Qué ID quiero marcar desde la parte superior –

1

Sólo trate como este método simple ....

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