ios - 将底线边框添加到 TextView - iOS

标签 ios swift uitextview

将底线边框添加到 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/

相关文章:

ios - 将应用程序提交到 iTunes Connect 时排除 iPod

ios - 如何在 Swift 的 tableView 单元格中添加一个开关?

ios - 移动到闭包内的另一个 Storyboard

ios - 如何为SwiftTask框架实现zip功能?

ios - 在键盘演示中点击 UITextView 或 UITextField 时出现 UIScrollView 问题

ios - 在 Swift 中使用 touchesBegan

ios - 扩展 Swift 数组以复制 indexOfObject 函数

ios - Swift - 无法更改 tableView 部分中的图像

iphone - 我的应用程序中的水平分页

ios - UICollectionView 单元格 UI 水平分页随机消失