想要具有固定字体和字体大小的多行标签

发布于 2024-11-28 18:02:56 字数 430 浏览 2 评论 0原文

我在我的应用程序中使用标签,并将标签的宽度指定为 100 像素。我放置在其中的内容会动态更改。内容有时不适合标签,如果文本不适合,它显示为abcd...。我将字体大小指定为 14,并将 ariel 指定为样式。

我要求的是,如果文本不适合,它应该像 textView 一样在下一行显示剩余的文本。我的要求是仅使用标签。我还没有准备好减小字体大小,即 14 。

我所做的是使用 lineBreakMode 并将行数设置为零。

self.titleLabel2.lineBreakMode=UILineBreakModeCharacterWrap;
    self.titleLabel2.numberOfLines=0;

有人可以建议我一种方法来满足我的要求吗?

TNQ

迪纳卡

i am using a label in my app and given the width of the label as 100 pixel.The content which i place in it would change dynamically.The content sometimes doesn't fit in the label and if the text doesn't fit in, it displays as abcd.... i have given the font size as 14 and ariel as style.

what i require is if the text doesn't fit in ,it should display the remaining text in next line as a textView does.My requirement is to use only a label.I am not ready to reduce the font size i.e 14 .

what i have done is used lineBreakMode and set the number of lines to zero.

self.titleLabel2.lineBreakMode=UILineBreakModeCharacterWrap;
    self.titleLabel2.numberOfLines=0;

can some one suggest me a way to meet my requirement.

TNQ

dinakar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄟ。诗瑗 2024-12-05 18:02:56

只要标签足够高以适合所有行,您在示例代码中所做的操作就应该有效。如果您需要调整标签大小以动态适应文本,请参阅调整 UILabel 大小以适应?。

What you've done in your example code should work, as long as the label is tall enough to fit all the lines. If you need to resize the label to fit the text dynamically, see Sizing a UILabel to fit?.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文