Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyapuchka committed Jan 12, 2017
1 parent 77f1f70 commit e6e6ef8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#CHANGELOG

##1.2.0

- fixed loosing data detector info when updating text
- moved helper methods to public UITextView extension to easily add custom handling for toucher in arbitrary text ranges

##1.1.0

- added `setNeedsUpdateTrim` method to force update trimming
Expand Down
52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# ReadMoreTextView

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

![](screenshot.gif)

Expand All @@ -17,15 +17,59 @@ UITextView subclass with "read more"/"read less" capabilities.

textView.shouldTrim = true
textView.maximumNumberOfLines = 4
textView.readMoreText = "... Read more"
textView.readLessText = " Read less"
textView.attributedReadMoreText = NSAttributedString(string: "... Read more")
textView.attributedReadMoreText = 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.

```swift

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](https://github.com/CocoaPods/CocoaPods):

pod 'ReadMoreTextView'
` pod 'ReadMoreTextView' `

##License

Expand Down
8 changes: 5 additions & 3 deletions ReadMoreTextView.podspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
Pod::Spec.new do |s|

s.name = "ReadMoreTextView"
s.version = "1.1.0"
s.summary = 'UITextView subclass with "read more"/"read less" capabilities.'
s.version = "1.2.0"
s.summary = 'UITextView subclass with "read more"/"read less" capabilities and UITextView extensions to handle touches in characters range.'

s.description = <<-DESC
UITextView subclass with "Read more" behavior.
UITextView extensions to handle touches in characters range.
* Set "read more"/"read less" text as a String or NSAttributedString
* Set maximum number of lines to display
* Turn trim on/off
* Live updates and setup in Interface Builder
* Live updates and setup in Interface Builder
* Use UITextView extension methods to detect touches in arbitrary text ranges.
DESC

s.homepage = "http://ilya.puchka.me/custom-uitextview-in-swift/"
Expand Down
2 changes: 1 addition & 1 deletion Sources/UITextView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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.
Return `self` in `test` if text view should intercept the touch event or `nil` otherwise.
*/
public func hitTest(pointInGliphRange aPoint: CGPoint, event: UIEvent?, test: (Int) -> UIView?) -> UIView? {
guard let charIndex = charIndexForPointInGlyphRect(point: aPoint) else {
Expand Down

0 comments on commit e6e6ef8

Please sign in to comment.