swift - 在拖放之间丢失 NSAttributedString 的属性
问题描述
在 UICollectionView 和另一个 UIView 之间拖动,我得到 NSAttributedString 但没有 .font 属性。
掉落功能:
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
session.loadObjects(ofClass: NSAttributedString.self, completion: { providers in
let dropPoint = session.location(in: self)
for attributedString in providers as? [NSAttributedString] ?? [] {
\\ gets here
for attr in attributedString.attributes(at: 0, effectiveRange: nil) {
print(attr.key, attr.value) // no attributes to print
}
}
})
}
和拖动功能:
func dragItemFor(indexPath: IndexPath) -> [UIDragItem]{
if let cell = eiCollectionView.cellForItem(at: indexPath) as? EiCollactionViewCell {
if let attributedString = cell.label.attributedText {
for attr in attributedString.attributes(at: 0, effectiveRange: nil) {
print("pre drag vc: ",attr.key, attr.value)// prints the font
}
let dragItem = UIDragItem(itemProvider: NSItemProvider(object: attributedString))
dragItem.localObject = attributedString
return [dragItem]
}
}
return []
}
解决方案
问题是您的属性字符串没有开始的属性。.SFUIDisplay
不是字体值。这只是说“默认”的一种方式。如果你想要一个字体,你需要设置一个字体。
推荐阅读
- ios - 我是否需要在 Sign in with Apple 中完成 OAuth 流程(访问令牌的交换码)?
- python - OSError、Type22Error 和其他一些让我难过的问题
- javascript - 我怎样才能得到数据 int Jade
- javascript - reactjs.org 代码中的示例 ReactJS 无法与 JSX 一起使用
- html - li 元素堆叠而不对齐
- c - 你会如何解释这个反汇编列表?
- automated-tests - 在赛普拉斯的同一测试中两次调用 cy.server() 是否可以
- swiftui - SwiftUI - 如何使用按钮显示文本,然后使用计时器
- sql-server - 在不授予权限的情况下通过 SQL 查询获取磁盘的全部容量?
- django-rest-framework - Django 可写嵌套序列化器 - 错误非空约束