TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2015 |
Maintained by Olivier Halligon.
This pod contains categories on NSAttributedString
to add a lot of very useful convenience methods to manipulate attributed strings.
Convenience methods include:
setFont:range:
and fontAtIndex:effectiveRange:
)setTextColor:range:
and textColorAtIndex:effectiveRange:
)It also contains:
UIFont
to build a font given its postscript name and derive a bold/italic font from a standard one and vice-versa.UILabel
to make it easier to detect the character at a given coordinate, which is useful to detect if the user tapped on a link (if the character as a given tapped CGPoint
has an associated NSURL
) and similar stuffNote that for advanced URL detection, you should still prefer
UITextView
(configuring it witheditable=NO
) and its dedicated delegate methods instead of usingUILabel
(which does not publicly expose itsNSLayoutManager
to properly compute the exact way its characters are laid out, forcing us to recreate the TextKit objects ourselves, contrary toUITextView
).
The source code is fully commented and documentation is auto-generated here.
There is also some help pages in the repository's wiki.
The suggested installation is via CocoaPods. Simply add the following line to your Podfile
:
pod 'OHAttributedStringAdditions'
Then do a pod install
.
A demo project is provided in the repository. Don't hesitate to open Example/AttributedStringDemo.xcworkspace
and play with it.
If you have CocoaPods, you can even try that Sample project even if you don't have cloned the project yet, by using pod try OHAttributedStringAdditions
in your terminal.
#import <UIKit/UIKit.h>
in the pch file, or replacing UIColor
and UIFont
classes with NSColor
and NSFont
(using macros to switch from one to another depending on the SDK), but that still requires some work and tests.Note: The original code of these categories comes from my old
OHAttributedLabel
pod, which is now deprecated as I don't have time to maintain it. As this previous implementation was based on CoreText and was not compatible (sometimes even crash) with UIKit/TextKit, I converted those categories to create this UIKit-compliantNSAttributedString
, not related to CoreText andOHAttributedLabel
anymore and that now work with latest versions of iOS/UIKit/TextKit.
This component is under the MIT Licence (See the LICENSE
file).