首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在拖放之间丢失NSAttributedString的属性

在拖放之间丢失NSAttributedString的属性
EN

Stack Overflow用户
提问于 2018-09-12 06:14:13
回答 1查看 116关注 0票数 1

在UICollectionView和另一个UIView之间拖动时,我得到了NSAttributedString,但没有.font属性。

drop函数:

代码语言:javascript
复制
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

            }
        }
    })
}

和拖动功能:

代码语言:javascript
复制
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 []
}
EN

回答 1

Stack Overflow用户

发布于 2018-09-12 07:31:16

问题是你的属性字符串一开始就没有属性。.SFUIDisplay不是字体值。这只是一种表达“默认”的方式。如果你想要字体,你需要设置字体。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52284873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档