Giter VIP home page Giter VIP logo

readmoretextview's Introduction

No Maintenance Intended Version License Platform Swift Version

ReadMoreTextView

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.

readmoretextview's People

Contributors

ilyapuchka avatar ssathy2 avatar amitaib avatar dchohfi avatar pipecamo avatar raonivaladares avatar

Stargazers

 avatar 0x1306a94 avatar mui_z avatar Why$time avatar Muhammad Umer avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.