Skip to content

Instantly share code, notes, and snippets.

@Cyanide7523
Created September 14, 2018 07:19
Show Gist options
  • Save Cyanide7523/1c5879ca5b5b61668b01738913059ec4 to your computer and use it in GitHub Desktop.
Save Cyanide7523/1c5879ca5b5b61668b01738913059ec4 to your computer and use it in GitHub Desktop.
Extension function for scrolling textView scroll to bottom
//
// 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