2017-06-19 49 views

回答

0

基本上,您可以採取另一種方法解決您的問題,方法是在您的UITextView的左側添加一個帶有填充背景的UIViewCALayer。只需將其寬度值設置爲2-3即可將其等同爲「左邊框」。

extension UITextView { 
    func setLeftBorder(color: UIColor, width:CGFloat = 2.0) { 
     let borderFrame = CGRect(x: 0, y: 0, width: width, height: self.frame.width) 
     let borderView = UIView(frame: borderFrame) 
     borderView.backgroundColor = color 
     self.addSubview(borderView) 
    } 
} 

但是,當你的UITextView開始滾動時,問題將無法解決。所以我認爲你應該將它們嵌入另一個UIView。這是我使用AutoLayout的最終解決方案: My Solution - Click to see the image

+0

我正在製作一個TextEditor,所以,這個裝飾器必須能夠改變它的尺寸並隨文本一起滾動 –

相關問題