gpt4 book ai didi

ios - 向上或向下滚动 TextView 的按钮

转载 作者:行者123 更新时间:2023-11-28 15:02:30 24 4
gpt4 key购买 nike

我知道如何创建具有滚动功能的 TextView ,但这需要您触摸 TextView 内部并手动向上或向下滚动文本。我想创建一个 UITextview 和两个按钮。这些按钮充当滚动按钮,一个向上滚动,另一个向下滚动,让用户控制滚动速度。我见过的许多示例都涉及自动滚动到底部,这不是我想要的。谁能建议一种在按下按钮时向上或向下滚动一到三行的方法?非常感谢!

最佳答案

    @IBOutlet weak var textView: UITextView!

@IBAction func upButton(_ sender: Any) {
let currentOffset = textView.contentOffset
let padding : CGFloat = 10 // Change as your choice
textView.setContentOffset(
CGPoint(
x: currentOffset.x,
y: currentOffset.y - padding < 0 ? 0 : currentOffset.y - padding
),
animated: true
)

}


@IBAction func downButton(_ sender: Any) {
let currentOffset = textView.contentOffset
let contentHeight = textView.contentSize.height
let padding : CGFloat = 10.0 // Change as your choice
textView.setContentOffset(
CGPoint(
x: currentOffset.x,
y: currentOffset.y + padding > contentHeight ? contentHeight : currentOffset.y + padding
),
animated: true
)
}

关于ios - 向上或向下滚动 TextView 的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48758929/

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