gpt4 book ai didi

iphone - UItextField 文本位于中心

转载 作者:行者123 更新时间:2023-11-29 04:48:19 25 4
gpt4 key购买 nike

我有这个文本字段

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

最佳答案

将下面的行设置为您的代码。

textPredmet.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

它将垂直设置文本中心。

  textPredmet.textAlignment = UITextAlignmentCenter;

它将水平设置文本中心。

另外,从代码中删除以下行。

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

关于iphone - UItextField 文本位于中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9293944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com