在UICollectionView和另一个UIView之间拖动时,我得到了NSAttributedString,但没有.font属性。
drop函数:
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 []
}发布于 2018-09-12 07:31:16
问题是你的属性字符串一开始就没有属性。.SFUIDisplay不是字体值。这只是一种表达“默认”的方式。如果你想要字体,你需要设置字体。
https://stackoverflow.com/questions/52284873
复制相似问题