这是我的情况.我有3个不同的数据(最后忽略一个钱,它将不包括在内),如下所示:
但是第一个数据(音乐类型)可能会更长,最终应该是这样的:
因此,我必须遵守多个约束:音乐类型应该跟随事件类型数据,在所需的任何行上.必须包含事件类型的徽标.当然,总宽度不应大于它的超视宽度.
我根本不知道从哪里开始音乐类型和事件类型.我试过,但我不知道如何使用动态宽度的<=宽度约束.
我正在处理Storyboard.
如果你尝试使用大量的自动布局规则来解决它,那就太难了.如果你能够使用它,有一个更简单的建议:NSAttributedString和NSTextAttachment.归属字符串是附加格式的字符串(粗体,斜体,对齐,颜色等),但您也可以将图像附加到属性字符串中,并且它们只是与文本一起绘制.
这是一个帮助您入门的示例:
// create an NSMutableAttributedString that we'll append everything to
let fullString = NSMutableAttributedString(string: "Start of text")
// create our NSTextAttachment
let image1Attachment = NSTextAttachment()
image1Attachment.image = UIImage(named: "awesomeIcon.png")
// wrap the attachment in its own attributed string so we can append it
let image1String = NSAttributedString(attachment: image1Attachment)
// add the NSTextAttachment wrapper to our full string, then add some more text.
fullString.appendAttributedString(image1String)
fullString.appendAttributedString(NSAttributedString(string: "End of text"))
// draw the result in a label
yourLabel.attributedText = fullString
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
524 次 |
| 最近记录: |