How to set text position to bottom in textField

狂风中的少年 提交于 2021-02-07 13:38:18

问题


I created a textField through code using the following code

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


回答1:


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.




回答2:


txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;

If you want the text to be in the center you can use ,

txtObj.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;



回答3:


Swift 4,5 solution:

txtObj.contentVerticalAlignment =  .bottom


来源:https://stackoverflow.com/questions/8906649/how-to-set-text-position-to-bottom-in-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!