UItextFiled текст по центру - PullRequest
       4

UItextFiled текст по центру

0 голосов
/ 15 февраля 2012

У меня есть этот текст./////////////

 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];

Ответы [ 2 ]

1 голос
/ 15 февраля 2012

Установите ниже строки вашего кода.

textPredmet.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

Устанавливает текстовый центр вертикально.

  textPredmet.textAlignment = UITextAlignmentCenter;

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

Также удалите ниже строки из вашего кода.

[textPredmet drawTextInRect:CGRectMake( 30,55,200,40)];
0 голосов
/ 15 февраля 2012

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...