本文介绍了如何调整从底部的UILabel的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何的UILabel 可从底部对齐。让说,我的标签,可容纳三线text.If的输入文字是单行线,那么这条线应该在label.Please底部参考下面的图片为更好的理解。橙色区域是label.Currently的全帧它有一条线,它对准中心。因此,我想,它应该始终对准了多少线下不管。How the UILabel can be aligned from bottom. Let say, my label can hold three line of text.If the input text is single line, then this line should come bottom of the label.Please refer the below image for better understanding. The orange area is the full frame of label.Currently it has one line and it is aligned center. So what I want is, it should always aligned bottom regardless of how many lines.请提出你的想法。感谢你。推荐答案下面是这样做的两种方式...Here are two ways of doing that... 1 第一套 numberOfLines 0,然后使用 sizeToFit 属性的UILabel 让你的的UILabel 显示屏以其 contentSize 。1. First set numberOfLines to 0 and then use sizeToFit property of UILabel so your UILabel display with its contentSize.yourLabel.numberOfLines = 0;[yourLabel sizeToFit];从这个链接查看更多信息:垂直内一个UILabel 对齐文本 2 另一种选择是采取的UITextField ,而不是的UILabel ,并设定 userInteractionEnabled $以 NO 象下面...2. Another option is to take UITextField instead of UILabel and set userInteractionEnabled to NO like below...[yourTextField setUserInteractionEnabled:NO];然后设置 contentVerticalAlignment 属性底部像下面......and then set the contentVerticalAlignment property to bottom like below....[yourTextField setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom]; 更新此外,与的UITextField ,我们无法实现多行。因此,而不是我们可以使用的UITextView ,并设置其 userInteractionEnabled 到 NO 。然后,使用下面的code,使其底部对齐。Also, with UITextField, we can't achieve multiple lines. So instead we can use UITextView and set its userInteractionEnabled to NO. Then, use the code below to make it bottom aligned.CGFloat topCorrect = ([label bounds].size.height - [label contentSize].height);topCorrect = (topCorrect <0.0 ? 0.0 : topCorrect);label.contentOffset = (CGPoint){.x = 0, .y = -topCorrect}; 这篇关于如何调整从底部的UILabel的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 07:57