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 设置左上对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为 iOS 应用程序的 UILabel 设置左上对齐?


基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01