• This repository has been archived on 17/Jun/2021
  • Stars
    star
    307
  • Rank 136,109 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UITextView subclass with "read more"/"read less" capabilities

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.

More Repositories

1

URLFormat

Type safe url pattern matching without regular expressions and arguments type mismatches based on parser combinators.
Swift
215
star
2

Gauges

Gauges gives you a nice looking circular progress view.
Swift
87
star
3

ToggleUI

Swift
70
star
4

SwiftNIOMock

A web server based on SwiftNIO designed to be used as a mock server in UI automation tests
Swift
54
star
5

Deeper

Put some order in your deep links handling
Swift
40
star
6

Interplate

Templates and type-safe string formatting based on Swift 5 string interpolation
Swift
38
star
7

graphique

Experimental GraphQL query builders
Swift
24
star
8

clrex

Simple script to generate UIColor factory methods from clr files
Swift
20
star
9

SourceKittenEditorExtension

Xcode Source Editor Extension that demonstrates how to use SourceKitten via XPC Service
Swift
19
star
10

dipgen

Code generator for Dip https://github.com/AliSoftware/Dip
Swift
18
star
11

LightweightNetworking-ObjC

Source code for blogpost - http://ilya.puchka.me/networking-use-case/
Objective-C
15
star
12

HFWeekApp

Simple OS X app to display current HelloFresh Week
Objective-C
15
star
13

SwiftNetworking

Implementation of network layer in Swift 2.0
Swift
15
star
14

cli-mate

Swift
11
star
15

YoutubeAPI

Objective-C
7
star
16

common-parsers

Swift
7
star
17

ViewControllerThinning

How to keep view controller as thin as possible
Swift
6
star
18

GhostAPI

Swift client for Ghost API.
Swift
5
star
19

SwiftGitHubAction

Github Action for Swift
Dockerfile
4
star
20

Currency

Swift
3
star
21

COOLKit

Objective-C
2
star
22

ShapesRecognition

Swift
2
star
23

MixedFramework

Objective-C
2
star
24

Flask-PyApns

Flask brindge for PyAPNS
Python
2
star
25

SwiftFeatures

Swift
2
star
26

StencilJS

JavaScriptCore extension for Stencil
Swift
1
star
27

SwiftTwo

Swift
1
star
28

PyObjC-FlaskAdmin

PyObjC and FlaskAdmin used together to provide auto generated admin interface based on XCode Core Data model
Python
1
star
29

SwiftStringInterpolation

Swift
1
star
30

Dependency-Injection-in-Cocoa

Materials for talk "Dependency Injection in Cocoa"
Objective-C
1
star