ReadMoreTextView 3.0.0

ReadMoreTextView 3.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Ilya Puchka.


Downloads

Total48,172
Week0
Month2,651

Installs

Apps1,289
Pod Tries13
Test Targets86
powered by Segment

GitHub

Stars80
Watchers2
Forks22
Issues1
Contributors4
Pull Requests0

Code

Files2
LOCLines of Code 310


UITextView subclass with "read more"/"read less" capabilities and UITextView extensions to handle touches in characters range.

Usage

let textView = ReadMoreTextView()

textView.text = "Lorem ipsum dolor ..."

textView.shouldTrim = true
textView.maximumNumberOfLines = 4
textView.attributedReadMoreText = NSAttributedString(string: "... Read more")
textView.attributedReadLessText = NSAttributedString(string: " Read less")

Custom touches handling.

This project also includes few helper methods that will allow you to detect and handle touches in arbitrary text ranges. This way you can for exapmle implement custom links handling in your UITextView subclass. ReadMoreTextView uses these methods itself to detect touches in "read more"/"read less" action areas.

extension UITextView {

	/**
	 Calls provided `test` block if point is in gliph range and there is no link detected at this point.
	 Will pass in to `test` a character index that corresponds to `point`.
	 Return `self` in `test` if text view should intercept the touch event or `nil` otherwise.
	 */
	public func hitTest(pointInGliphRange:event:test:) -> UIView?
	
	/**
	 Returns true if point is in text bounding rect adjusted with padding.
	 Bounding rect will be enlarged with positive padding values and decreased with negative values.
	 */
	public func pointIsInTextRange(point:range:padding:) -> Bool
	
	/**
	 Returns index of character for glyph at provided point. Returns `nil` if point is out of any glyph.
	 */
	public func charIndexForPointInGlyphRect(point:) -> Int?
	
}

extension NSLayoutManager {

    /**
     Returns characters range that completely fits into container.
     */
    public func characterRangeThatFits(textContainer:) -> NSRange
    
    /**
     Returns bounding rect in provided container for characters in provided range.
     */
    public func boundingRectForCharacterRange(range:inTextContainer:) -> CGRect

}

Installation

Available in Cocoa Pods:

pod 'ReadMoreTextView'

License

ReadMoreTextView is available under the MIT license.