标签:
效果如下:
ViewController.h
1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @end
ViewController.m
1 #import "ViewController.h" 2 3 @interface ViewController () 4 - (void)layoutUI; 5 @end 6 7 @implementation ViewController 8 9 - (void)viewDidLoad { 10 [super viewDidLoad]; 11 12 [self layoutUI]; 13 } 14 15 - (void)didReceiveMemoryWarning { 16 [super didReceiveMemoryWarning]; 17 // Dispose of any resources that can be recreated. 18 } 19 20 - (void)layoutUI { 21 UITextView *txtVDataDetectorTypes = [[UITextView alloc] initWithFrame:CGRectInset(self.view.bounds, 20, 20)]; 22 txtVDataDetectorTypes.font = [UIFont systemFontOfSize:17]; 23 txtVDataDetectorTypes.backgroundColor = [UIColor colorWithRed:0.925 green:1.000 blue:0.721 alpha:1.000]; 24 //在不可编辑的状态下有效,设置文本视图的数据检测器类型;默认值是UIDataDetectorTypeNone 25 txtVDataDetectorTypes.editable = NO; 26 txtVDataDetectorTypes.dataDetectorTypes = UIDataDetectorTypeAll; 27 28 txtVDataDetectorTypes.text = @"详细如下: 29 http://www.apple.com/ 30 联系方式: 31 158-0000-0000 32 邮箱: 33 xxx@apple.com"; 34 [self.view addSubview:txtVDataDetectorTypes]; 35 36 /* 37 typedef NS_OPTIONS(NSUInteger, UIDataDetectorTypes) { 38 UIDataDetectorTypePhoneNumber = 1 << 0, // Phone number detection 39 UIDataDetectorTypeLink = 1 << 1, // URL detection 40 #if __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED 41 UIDataDetectorTypeAddress = 1 << 2, // Street address detection 42 UIDataDetectorTypeCalendarEvent = 1 << 3, // Event detection 43 #endif 44 45 UIDataDetectorTypeNone = 0, // No detection at all 46 UIDataDetectorTypeAll = NSUIntegerMax // All types 47 }; 48 */ 49 } 50 51 @end
标签:
原文地址:http://www.cnblogs.com/huangjianwu/p/4580267.html