xcode 如何在textField中将文本位置设置为底部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8906649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set text position to bottom in textField
提问by surendher
I created a textField through code using the following code
我使用以下代码通过代码创建了一个 textField
UITextField *txtObj=[UITextField alloc]initWithFrame:CGRectMake(88,100,80,33)];
I am getting the textfield as i planned, but the text we type in that text field seems to appear in the top area of text but not in bottom.I tried to align it but i got tired. Can anyone tell me what's the solution
我正在按计划获取文本字段,但我们在该文本字段中键入的文本似乎出现在文本的顶部区域而不是底部。我试图对齐它,但我累了。谁能告诉我解决方案是什么
回答by The dude
it should be:
它应该是:
txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
This property is inherited from the UIControl class. The default is: UIControlContentVerticalAlignmentTop , that's why you get the text on top.
该属性继承自 UIControl 类。默认为: UIControlContentVerticalAlignmentTop ,这就是为什么您将文本置于顶部的原因。
回答by Sharme
txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
If you want the text to be in the center you can use ,
如果您希望文本位于中心,您可以使用 ,
txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
回答by Ali Alaoi
Swift 4,5 solution:
Swift 4,5 解决方案:
txtObj.contentVerticalAlignment = .bottom