iOS_带下划线的Label
2015-12-14 16:32
417 查看
iOS_带下划线的Label_带点击和长按事件工程下载:点击打开链接【一】【PCH创建步骤】
1. 在Supporting Files下面,右键 New File, 选择 Other 里面的PCH File 2. 点击相应的TARGETS --->Build Setting ,搜索Prefix Header 3. 将Precompile Prefix Header 勾选为YES 4. 将左上角 项目的名字拷贝一下, 双击Prefix Header一栏, 填入:【项目的名字/Beyond.pch】
#import <Availability.h> #ifndef __IPHONE_3_0 #warning "This project uses features only available in iOS SDK 3.0 and later." #endif #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #endif【2】【添加libxml库】工程-->targets-->Build Phases-->添加libxml2.dylib【3】【解决libxml 找不到的问题】
导入了libxml2.dylib,但是却提示libxml/XXX.h file not found,那是因为路径无法找到这个libxml2.dylib框架
工程-->targets-->Build Settings,查找:“Header search paths”
在Header search paths 输入:${SDK_DIR}/usr/include/libxml2
【4】【将整个LinkLabel拖进项目中】
【5】【控制器里的使用示例代码】
#import "CXAHyperlinkLabel.h"#import "NSString+CXAHyperlinkParser.h"@interface BeyondCtrl (){CXAHyperlinkLabel *_label;}@end
- (void)viewDidLoad {[super viewDidLoad];_label = (CXAHyperlinkLabel *)self.lastView;NSArray *URLs;NSArray *URLRanges;NSAttributedString *as = [self attributedString:&URLs URLRanges:&URLRanges];// _label = [[CXAHyperlinkLabel alloc] initWithFrame:CGRectZero];_label.numberOfLines = 0;_label.backgroundColor = [UIColor clearColor];_label.attributedText = as;[_label setURLs:URLs forRanges:URLRanges];_label.URLClickHandler = ^(CXAHyperlinkLabel *label, NSURL *URL, NSRange range, NSArray *textRects){[[[UIAlertView alloc] initWithTitle:@"URLClickHandler" message:[NSString stringWithFormat:NSLocalizedString(@"Click on the URL %@", nil), [URL absoluteString]] delegate:nil cancelButtonTitle:NSLocalizedString(@"Dismiss", nil) otherButtonTitles:nil] show];};_label.URLLongPressHandler = ^(CXAHyperlinkLabel *label, NSURL *URL, NSRange range, NSArray *textRects){[[[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"URLLongPressHandler for URL: %@", [URL absoluteString]] delegate:nil cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:nil] showInView:self.view];};}#pragma mark - privates- (NSAttributedString *)attributedString:(NSArray *__autoreleasing *)outURLsURLRanges:(NSArray *__autoreleasing *)outURLRanges{NSString *HTMLText = @"An inline link may display a modified version of the content; for instance, instead of an image, a <a href='/wiki/Thumbnail' title='Thumbnail'>thumbnail</a>, <a href='/wiki/Image_resolution' title='Image resolution'>low resolution</a> <a href='/wiki/Preview_(computing)' title='Preview (computing)'>preview</a>, <a href='/wiki/Cropping_(image)' title='Cropping (image)'>cropped</a> section, or <a href='/wiki/Magnification' title='Magnification'>magnified</a> section may be shown. The full content will then usually be available on demand, as is the case with <a href='/wiki/Desktop_publishing' title='Desktop publishing'>print publishing</a> software – e.g. with an external link. This allows for smaller file sizes and quicker response to changes when the full linked content is not needed, as is the case when rearranging a <a href='/wiki/Page_layout' title='Page layout'>page layout</a>.";NSArray *URLs;NSArray *URLRanges;UIColor *color = [UIColor blackColor];UIFont *font = [UIFont fontWithName:@"Baskerville" size:19.];NSMutableParagraphStyle *mps = [[NSMutableParagraphStyle alloc] init];mps.lineSpacing = ceilf(font.pointSize * .5);NSShadow *shadow = [[NSShadow alloc] init];shadow.shadowColor = [UIColor whiteColor];shadow.shadowOffset = CGSizeMake(0, 1);NSString *str = [NSString stringWithHTMLText:HTMLText baseURL:[NSURL URLWithString:@"http://en.wikipedia.org/"] URLs:&URLs URLRanges:&URLRanges];NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName : color,NSFontAttributeName : font,NSParagraphStyleAttributeName : mps,NSShadowAttributeName : shadow,}];[URLRanges enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){[mas addAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor],NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)} range:[obj rangeValue]];}];*outURLs = URLs;*outURLRanges = URLRanges;return [mas copy];}
【6】【设置Label的UserInteraction为YES】
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- Jquery跨域获得Json时invalid label错误的解决办法
- js 为label标签和div标签赋值的方法
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件
- Android和IOS的浏览器中检测是否安装某个客户端的方法