How to set top-left alignment for UILabel for iOS application?(如何为 iOS 应用程序的 UILabel 设置左上对齐?)
问题描述
我在我的 nib 文件中添加了一个标签,然后它需要对该标签进行左上对齐.由于我在运行时提供文本,因此不确定有多少行.因此,如果文本仅包含单行,则它显示为垂直居中对齐.该对齐方式与我前面的相应标签不匹配.
I have added one label in my nib file, then its required to have top-left alignment for that lable. As I am providing text at runtime so its not sure that how much lines there are. So if text contains only single line then it appears as vertical-center aligned. That alignment is not matching with my respective lable in front of it.
例如:
这看起来很奇怪:(
有什么方法可以让标签文本正确设置为左上对齐?
推荐答案
这里不再重复解释,而是链接到这个比较广泛的&高度评价的问题/答案:
Rather than re-explaining, I will link to this rather extensive & highly rated question/answer:
在 UILabel 中将文本垂直对齐到顶部
简短的回答是否定的,Apple 并没有让这变得简单,但可以通过更改帧大小来实现.
The short answer is no, Apple didn't make this easy, but it is possible by changing the frame size.
这篇关于如何为 iOS 应用程序的 UILabel 设置左上对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!