ReadMoreTextView
具有“阅读更多”/“阅读更少”功能和使用UITextView扩展来处理文本范围内触摸的UITextView子类。
用法
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")
自定义触摸处理。
此项目还包括一些辅助方法,可以检测和处理任意文本范围内的触摸。这样,例如,您可以在自己的UITextView
子类中实现自定义链接处理。`ReadMoreTextView`本身也使用这些方法来检测“阅读更多”/“阅读更少”操作区域的触摸。
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
}
安装
在Cocoa Pods中可用
pod 'ReadMoreTextView'
许可证
ReadMoreTextView 适用于MIT 许可证。