Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (39 sloc) 1.15 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.
func clear() {
text = ""
attributedText = NSAttributedString(string: "")
}
/// SwifterSwift: Scroll to the bottom of text view
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
func scrollToTop() {
// swiftlint:disable:next legacy_constructor
let range = NSMakeRange(0, 1)
scrollRangeToVisible(range)
}
/// SwifterSwift: Wrap to the content (Text / Attributed Text).
func wrapToContent() {
contentInset = UIEdgeInsets.zero
scrollIndicatorInsets = UIEdgeInsets.zero
contentOffset = CGPoint.zero
textContainerInset = UIEdgeInsets.zero
textContainer.lineFragmentPadding = 0
sizeToFit()
}
}
#endif
You can’t perform that action at this time.