UITextView 替换UILable显示链接文本

来源:互联网 发布:艾瑞莉娅冰霜之刃淘宝 编辑:程序博客网 时间:2024/05/21 22:50

比如手机号码和 Web 地址时,内置的UILable 类不是很智能。UITextView文本视图提供一个称为 dataDetectorTpes 的新属性,它指定要转换为可点击 URL 的数据类型。

现有类型是手机号码(UIDataDetectorTypePhoneNumber) 和链接 (UIDataDetectorTypesLink),要启用所有类型,可选择这里使用的所有标记(UIDataDetectorTypeAll)

用TextView 实例替代UILable实例时,一定要禁用滚动。即editable属性设为NO 。使用换行字符常量(\n)进行换行。


   UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(40.0f, 25.0f, 236.0f, 86.0f)];
    textView.text=@"http://www.baidu.com\n\r 303-555-1212";
    textView.editable=NO;
    textView.dataDetectorTypes=UIDataDetectorTypeAll;
    [self.view addSubview:textView];

原创粉丝点击