2012-02-15 2 views
0

У меня есть этот TextFieldUItextFiled текст в центре

enter image description here

, который делает текст по центру? //////////////////////// ///////////

textPredmet = [[UITextField alloc] initWithFrame:CGRectMake(20, 55, 200, 40)]; 
    textPredmet.borderStyle = UITextBorderStyleNone; 
    textPredmet.textColor = [UIColor blackColor]; //text color 
    textPredmet.font = [UIFont systemFontOfSize:15.0]; //font size 

    [textPredmet drawTextInRect:CGRectMake(30,55,200,40)]; 

    textPredmet.placeholder = @"Введите текст"; //place holder 
    textPredmet.backgroundColor = [UIColor clearColor]; //background color 
    textPredmet.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support 
    textPredmet.keyboardType = UIKeyboardTypeDefault; // type of the keyboard 
    textPredmet.returnKeyType = UIReturnKeyDone; // type of the return key 
    textPredmet.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right 
    textPredmet.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed 
    textPredmet.background = [UIImage imageNamed:@"input.png"]; 
    textPredmet.textAlignment=UITextAlignmentLeft+1; 
    [self.view addSubview:textPredmet]; 
+0

Что делает UITextAlignmentLeft + 1 на самом деле? Вы должны использовать UITextAlignmentCenter. –

ответ

1

Set ниже линии кода.

textPredmet.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 

Он установит текстовый центр по вертикали.

textPredmet.textAlignment = UITextAlignmentCenter; 

Он установит текстовый центр по горизонтали.

Кроме того, удалите нижние строки из кода.

[textPredmet drawTextInRect:CGRectMake(30,55,200,40)]; 
0

Я думаю, UITextAlignmentLeft + 1 == UITextAlignmentCenter

Смежные вопросы