【问题标题】:Subview button in textview disappearing when changing NSMutableAttributedString until scrolled to the top更改 NSMutableAttributedString 直到滚动到顶部时,文本视图中的子视图按钮消失
【发布时间】:2017-10-10 10:29:35
【问题描述】:

我一直在为我的文本视图创建一个突出显示系统,该系统足够大,可以启用滚动,在底部我添加了一个使用子视图的按钮,它充当下一个视图的 segue。

当我使用按钮下方的功能更改文本时,按钮消失(不可点击或不可见)。 当我滚动到文本视图的顶部然后再次向下滚动时,按钮会重新出现。有谁知道为什么?有没有办法刷新按钮的显示?

编辑:子视图计数在事件之前或之后不会改变。

func highlightText () {

    guard let text = self.textView.attributedText else {
        return
    }
    guard let range = self.textView.visibleBottomRange else {
        return
    }
    let attributedString = NSMutableAttributedString(attributedString:text)
    attributedString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.yellow , range: range)

    self.textView.attributedText = attributedString
}

【问题讨论】:

    标签: ios swift scroll uitextview subview


    【解决方案1】:

    在这里找到答案: Stackoverflow question

    使用: self.textView.layoutManager.allowsNonContiguousLayout = false; 允许子视图在更改文本视图的属性文本时保持可见

    【讨论】:

      猜你喜欢
      • 2015-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 2016-09-21
      • 2020-09-07
      相关资源
      最近更新 更多