问题
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