gpt4 book ai didi

ios - 通过 NSAttributedStringKey 的附件不可见

转载 作者:可可西里 更新时间:2023-11-01 02:00:18 25 4
gpt4 key购买 nike

可以通过 largeTitleTextAttributes 自定义新的大标题功能,(与任何其他属性一样) dictionary with NSAttributedStringKey 键。其中一个键是 NSAttachmentAttributeName/attachment

考虑一下:

let attachment = NSTextAttachment()
attachment.image = UIImage(named: "foo")
attachment.bounds = CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0)

var largeTitleTextAttributes: [NSAttributedStringKey: Any] = [:]
largeTitleTextAttributes[.attachment] = attachment
navigationBar.largeTitleTextAttributes = largeTitleTextAttributes

The problem is the attachment I assigned to the largeTitleTextAttributes attribute attachment is not visible.

如何将附件添加到属性字典中以便附件可见? (我不是在寻找 NSAttributedString初始化(附件:NSTextAttachment)

最佳答案

正如 Apple 的文档所说,您只能指定

You can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the text attribute keys described in NSAttributedStringKey.

但是你可以直接将UILabel设置为导航栏的标题 View ,比如使用以下代码

let image1Attachment = NSTextAttachment()
image1Attachment.image = UIImage(named: "bb")
image1Attachment.bounds = CGRect.init(x: 0.0, y: 0.0, width: 20, height: 20)
let image1String = NSAttributedString(attachment: image1Attachment)
let label: UILabel = UILabel.init(frame: (self.navigationController?.navigationBar.frame)!)
label.attributedText = image1String
if #available(iOS 11.0, *) {
self.navigationItem.titleView = label
}
else {
// Fallback on earlier versions
}

enter image description here

关于ios - 通过 NSAttributedStringKey 的附件不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46953028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com