我有这个textField
谁在中心做文字?///////////////////////////////////
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 :(得分:1)
在代码下方设置。
textPredmet.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
它将垂直设置文本中心。
textPredmet.textAlignment = UITextAlignmentCenter;
它将水平设置文本中心。
另外,从代码中删除以下行。
[textPredmet drawTextInRect:CGRectMake( 30,55,200,40)];
答案 1 :(得分:0)
我想,UITextAlignmentLeft + 1 == UITextAlignmentCenter