让textView文字垂直居中

    
    func textViewContentHeightChange(textView: UITextView) {
        DispatchQueue.main.async {
            if textView.bounds.size.height > textView.contentSize.height {
                var topDeviation = (textView.bounds.size.height - textView.contentSize.height)
                topDeviation = topDeviation < 0 ? 0 : topDeviation
                textView.contentOffset = CGPoint(x: 0, y: -topDeviation/2)
            }
        }
    }

猜你喜欢

转载自my.oschina.net/wayzhu/blog/1813999