Created
September 14, 2018 07:19
-
-
Save poca-p0ca/1c5879ca5b5b61668b01738913059ec4 to your computer and use it in GitHub Desktop.
Extension function for scrolling textView scroll to bottom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UITextViewExtensions.swift | |
// | |
// Created by Cyan on 2018. 9. 14.. | |
// Copyright © 2018 Cyan. All rights reserved. | |
// | |
import Foundation | |
import UIKit | |
extension UITextView{ | |
func scrollToBottom(){ | |
var _optionBeforeModifyingLayoutManager = false | |
if layoutManager.allowsNonContiguousLayout { | |
_optionBeforeModifyingLayoutManager = true | |
layoutManager.allowsNonContiguousLayout = false | |
} | |
let stringLength:Int = text.count | |
scrollRangeToVisible(NSMakeRange(stringLength - 1, 0)) | |
layoutManager.allowsNonContiguousLayout = _optionBeforeModifyingLayoutManager | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment