将底线边框添加到 TextView
的最佳方法是什么?
我已经试过了,但它似乎不起作用。它受 textview
滚动能力的影响,并且在 TextView
func addBottomBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.CGColor
border.frame = CGRectMake(0, self.frame.size.height - width, self.frame.size.width, width)
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
编辑: TextView 具有动态高度。
最佳答案
Swift 4 版本
func addBottomBorderWithColor() {
let border = CALayer()
border.backgroundColor = UIColor.black.cgColor
border.frame = CGRect(x: 0, y: yourTextArea.frame.height - 1, width: yourTextArea.frame.width, height: 1)
yourTextArea.layer.addSublayer(border)
self.view.layer.masksToBounds = true
}
关于ios - 将底线边框添加到 TextView - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38326249/