{"id":20010132,"url":"https://github.com/cxa/cxahyperlinklabel","last_synced_at":"2025-05-04T20:30:44.330Z","repository":{"id":6238124,"uuid":"7469920","full_name":"cxa/CXAHyperlinkLabel","owner":"cxa","description":"A drop-in and easy-to-use replacement for UILabel, supports handling link click and long press with block.","archived":false,"fork":false,"pushed_at":"2023-10-15T04:01:48.000Z","size":63,"stargazers_count":50,"open_issues_count":0,"forks_count":18,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T11:38:27.857Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cxa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-06T16:46:30.000Z","updated_at":"2024-02-20T02:40:28.000Z","dependencies_parsed_at":"2022-09-11T10:10:19.489Z","dependency_job_id":null,"html_url":"https://github.com/cxa/CXAHyperlinkLabel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FCXAHyperlinkLabel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FCXAHyperlinkLabel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FCXAHyperlinkLabel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FCXAHyperlinkLabel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cxa","download_url":"https://codeload.github.com/cxa/CXAHyperlinkLabel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252395175,"owners_count":21740977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T07:18:33.630Z","updated_at":"2025-05-04T20:30:43.914Z","avatar_url":"https://github.com/cxa.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CXAHyperlinkLabel\n\nA drop-in and easy-to-use replacement for UILabel for iOS 6, supports handling link click and long press with block that provides information for URL, the range and rect of URL.\n\n## Installation\n\n`CXAHyperlinkLabel` requires `CoreText.framework`, add it to *`Build Phases`* in your build target.\n\nDrop `CXAHyperlinkLabel.{h,m}` and `NSAttributedString+CXACoreTextFrameSize.{h,m}` into your project, and add `#include \"CXAHyperlinkLabel.h\"` to the top of classes which will use it.\n\n## How to Use\nUse it as the `UILabel`. To support links inside text, first you need to extract the URLs and the releated ranges, and tell `CXAHyperlinkLabel` with the method `- (void)setURL:range:`. To change the style of current touching link, set it with `linkAttributesWhenTouching` property. You can also tell `CXAHyperlinkLabel` what to do after clicking and/or long pressing a link with the block properties `URLClickHandler` and `URLLongPressHandler`.\n\n### Header At a Glance \n\n#### `CXAHyperlinkLabel.h`\n    @class CXAHyperlinkLabel;\n    \n    typedef void (^CXAHyperlinkLabelURLHandler)(CXAHyperlinkLabel *label, NSURL *URL, NSRange textRange, NSArray *textRects);\n    \n    @interface CXAHyperlinkLabel : UILabel\n    \n    @property (nonatomic, copy) CXAHyperlinkLabelURLHandler URLClickHandler;\n    @property (nonatomic, copy) CXAHyperlinkLabelURLHandler URLLongPressHandler;\n    @property (nonatomic, strong) NSDictionary *linkAttributesWhenTouching;\n    \n    - (void)setURL:(NSURL *)URL forRange:(NSRange)range;\n    - (void)setURLs:(NSArray *)URLs forRanges:(NSArray *)ranges;\n    - (void)removeURLForRange:(NSRange)range;\n    - (void)removeAllURLs;\n    - (NSURL *)URLAtPoint:(CGPoint)point effectiveRange:(NSRangePointer)effectiveRange;\n    \n    @end\n\n#### `NSAttributedString+CXACoreTextFrameSize.h`\n\n    @interface NSAttributedString (CXACoreTextFrameSize)\n    \n    - (CGSize)cxa_coreTextFrameSizeWithConstraints:(CGSize)size;\n    \n    @end\n\nClone and run the demo!\n\n## Bonus\n\nThis project also includes a category for NSString `NSString (CXAHyperlinkParser)` to parse simple HTML text (only `a` and `br` tags are supported). Extract links and ranges from plain text is also supported. It's very lightweight to save you from some huge library — Don't use a shotgun to kill a butterfly. \n\n`NSString (CXAHyperlinkParser)` requires `libxml2`. To install, drop `NSString+CXAHyperlinkParser.{h,m}` to your project, add `libxml2.2.dylib` to *`Build Phases`* and don't forget to set `$(SDK_ROOT)/usr/include/libxml2` in `Header Search Paths` of *`Build Settings`* in your build target.\n\n### Header At a Glance \n    \n    @interface NSString (CXAHyperlinkParser)\n    \n    + (NSString *)stringWithHTMLText:(NSString *)HTMLText URLs:(NSArray **)URLs URLRanges:(NSArray **)URLRanges;\n    + (NSString *)stringWithHTMLText:(NSString *)HTMLText baseURL:(NSURL *)baseURL URLs:(NSArray **)URLs URLRanges:(NSArray **)URLRanges;\n    + (void)getURLs:(NSArray **)URLs URLRanges:(NSArray **)URLRanges forPlainText:(NSString *)plainText;\n    \n    @end\n\n## Limitation\n\nIn order to get positions for links, `CXAHyperlinkLabel` draws its text from the ground-up via Core Text. Some rarely used or hard-to-implement attributes is currently not supported yet:\n\n* `NSStrikethroughStyleAttributeName`\n* `hyphenationFactor` of `NSParagraphStyle`\n\n## Creator\n\n* GitHub: \u003chttps://github.com/cxa\u003e\n* X: [@_realazy](https://x.com/_realazy)\n* Apps available in App Store: \u003chttp://lazyapps.com\u003e\n\n## License\n\nUnder the MIT license. See the LICENSE file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxa%2Fcxahyperlinklabel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcxa%2Fcxahyperlinklabel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxa%2Fcxahyperlinklabel/lists"}