ios - 如何在 iOS 中在其他标签下方显示两个单标签文本?

标签 ios objective-c autolayout uilabel

我想在另一个标签下方显示一个标签的文本。虽然文本应该从第一个标签的右侧开始,并且应该在另一个标签下方。请告诉我可以使用 ios 吗?

enter image description here

最佳答案

我找到了您问题的解决方案。它非常简单易懂。

NSMutableAttributedString *mutableAttributeStr = [[NSMutableAttributedString alloc]initWithString:@"User this is just a comment.This just a comment.This just a comment."];

NSAttributedString *attributeStr = [[NSAttributedString alloc]initWithString:@"\n" attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:8]}];

[mutableAttributeStr addAttribute:NSFontAttributeName value: [UIFont fontWithName:@"Helvetica-Bold" size:14.0] range:NSMakeRange(0, 4)];

[mutableAttributeStr appendAttributedString:attributeStr];

labelTextBelowAnotherLabel.numberOfLines = 0;

[labelTextBelowAnotherLabel setAttributedText:mutableAttributeStr];

上面的编码中我设置了 helvetica 粗体和字体大小供引用。如果您想更改为 systemBold,只需更改并根据您的要求设置字体大小即可。

谢谢-:)

关于ios - 如何在 iOS 中在其他标签下方显示两个单标签文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33073363/

相关文章:

ios - 从 js 到 Objective-C 的谓词

objective-c - 为什么 Objective-C block 在不将其复制到堆中的情况下仍然有效?

objective-c - 是否可以制作 NSBitmapImageRep 24 bpp 且没有 alpha channel ?

ios - 自动布局 iOS 11 工具栏 UIBarButtonItem 与 customView

ios - TableView不显示数据

objective-c - -fobjc-nonfragile-abi2 在 LLVM 编译器 2.0 : unknow argument?

ios - 以编程方式通过内容的摘要高度设置 uiview 高度,并将其添加到容器并调整其大小

ios - 从不兼容类型 'int' 分配给 'int (^__strong)(void)'

ios - 为什么表格 View 的大小与 iPhone X~iPhone XS Max 不同?

ios - 调整 UIButton 宽度/高度 (iOS) - 如何在不禁用自动布局的情况下解决?