是否可以将标签内的文本与“大”文本垂直对齐。帧 [英] Is it possible to vertically align text inside labels with a "large" frame

查看:74
本文介绍了是否可以将标签内的文本与“大”文本垂直对齐。帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有多个自定义单元格的表视图。单元格中的一些文本分布在2-4行之间,因此标签的高度足以容纳内容。

In my application I have multiple tableviews with custom cells. Some of the text in the cells are spread out on between 2-4 lines so the height of the label is large enough to contain the content.

然而在iPad上,屏幕较大,我希望文本显示在标签的左上角,而不是中间,就像使用<$时一样c $ c> numberOfLines 属性。我知道你可以水平对齐文本,但是必须可以将文本对齐到左上角吗?或者是不可能的。

However on iPad the screen is larger and I want the text to appear at the top left point of the label, not in the middle as it do when you use numberOfLines property. I know you can horizontally align the text, but it must be possible to align the text to the top left also? Or is it impossible.

屏幕截图:

推荐答案

不可能垂直对齐 UILabel 中的文本。但是,您可以使用 NSString sizeWithFont:方法动态更改标签的高度,并设置其 x y 如你所愿。

Its impossible to align the text in UILabel vertically. But, you can dynamically change the height of the label using sizeWithFont: method of NSString, and just set its x and y as you want.

作为替代方案,您可以使用 UITextField 。它支持 contentVerticalAlignment peoperty,因为它是 UIControl 的子类。您必须将 userInteractionEnabled 设置为 NO ,以防止用户在其上键入文字。

As an alternative you can use UITextField. It supports the contentVerticalAlignment peoperty as it is a subclass of UIControl. You have to set its userInteractionEnabled to NO to prevent user from typing text on it.

这篇关于是否可以将标签内的文本与“大”文本垂直对齐。帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆