Permalink
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (39 sloc) 1.18 KB
//
// UITextViewExtensions.swift
// SwifterSwift
//
// Created by Omar Albeik on 9/28/16.
// Copyright © 2016 SwifterSwift
//
#if canImport(UIKit) && !os(watchOS)
import UIKit
// MARK: - Methods
public extension UITextView {
/// SwifterSwift: Clear text.
public func clear() {
text = ""
attributedText = NSAttributedString(string: "")
}
/// SwifterSwift: Scroll to the bottom of text view
public func scrollToBottom() {
// swiftlint:disable next legacy_constructor
let range = NSMakeRange((text as NSString).length - 1, 1)
scrollRangeToVisible(range)
}
/// SwifterSwift: Scroll to the top of text view
public func scrollToTop() {
// swiftlint:disable next legacy_constructor
let range = NSMakeRange(0, 1)
scrollRangeToVisible(range)
}
/// SwifterSwift: Wrap to the content (Text / Attributed Text).
public func wrapToContent() {
contentInset = UIEdgeInsets.zero
scrollIndicatorInsets = UIEdgeInsets.zero
contentOffset = CGPoint.zero
textContainerInset = UIEdgeInsets.zero
textContainer.lineFragmentPadding = 0
sizeToFit()
}
}
#endif