1、UITextView:

A )      IOS7新增加的 UITextViewDelegate 方法:

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRangeNS_AVAILABLE_IOS(7_0);

这个代理方法是当用户点击UITextView中的超链接的时候回调次方法:

看代码:

1、首先viewController.h 文件中声明:<UITextViewDelegate>

2、viewController.m 中添加如下代码:

UITextView *textView;

- (void)viewDidLoad

{

[superviewDidLoad];

UIMenuItem *menuItem = [[UIMenuItemalloc]initWithTitle:@"替换"action:@selector(changeColor:)];

UIMenuController *menu = [UIMenuControllersharedMenuController];

[menu setMenuItems:[NSArrayarrayWithObject:menuItem]];

[menuItem release];

textView = [[UITextViewalloc]initWithFrame:[UIScreenmainScreen].applicationFrame];

textView.delegate =self;

textView.dataDetectorTypes =UIDataDetectorTypeAll;

textView.editable =NO;//(必须的)

textView.attributedText = [[NSAttributedStringalloc]initWithString:

@"My phone number is +8602980000000.\r\n"

"My personal web site www.xxxxxx.com.\r\n"

"My E-mail address is XXXXX@gmail.com.\r\n"

"I was born in 1900-01-01."];

[self.viewaddSubview:textView];

}

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange

{

if (URL)

{

NSLog(@"%@", [URLabsoluteString]);

return NO;

}

return YES;

}

- (void) changeColor:(id) sender

{

NSLog(@"changeColor");

}

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

if(action ==@selector(changeText:))

{

if(textView.selectedRange.length>0)

return YES;

}

return NO;

}

运行项目,点击其中的超链接就会回调 - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange 方法,然后在这个方法里实现项目需求。

注意:NSAttributedString 用法见:

http://blog.csdn.net/zfpp25_/article/details/9143299

http://blog.csdn.net/zfpp25_/article/details/8639215

点击网址后,控制台打印

附加:

UIMenuItem 效果:

B )

1、  UITextView IOS7 中新增加属性  BOOL selectable

@property(nonatomic,getter=isSelectable)BOOL selectableNS_AVAILABLE_IOS(7_0);// toggle selectability, which controls the ability of the user to select content and interact with URLs & attachments

用法:决定UITextView 中文本是否可以相应用户的触摸,主要指:1、文本中URL是否可以被点击;2、UIMenuItem是否可以响应

2、UITextView IOS7 中新增加属性  NSTextContainer *textContainer,意思是UITextView的文本输入容器,感觉是把以前的私有API公开了出来!有了这个 属性,就可以设置文本的对齐方式等等

// Set and get the text container for the text view

@property(nonatomic,readonly)NSTextContainer *textContainerNS_AVAILABLE_IOS(7_0);

例如:

textView.textContainer.lineBreakMode =NSLineBreakByTruncatingTail;

lineBreakMode 的其他参数如下:

typedef enum {
   UILineBreakModeWordWrap = 0,        以单词为单位换行,以单位为单位截断。
   UILineBreakModeCharacterWrap,       以字符为单位换行,以字符为单位截断。
   UILineBreakModeClip,                        以单词为单位换行。以字符为单位截断。
   UILineBreakModeHeadTruncation,     以单词为单位换行。如果是单行,则开始部分有省略号。如果是多行,则中间有省略号,省略号后面有4个字符。
   UILineBreakModeTailTruncation,         以单词为单位换行。无论是单行还是多行,都是末尾有省略号。
   UILineBreakModeMiddleTruncation,    以单词为单位换行。无论是单行还是多行,都是中间有省略号,省略号后面只有2个字符 
} UILineBreakMode;

3、  UITextView IOS7 中新增加属性  BOOL editable

By default, users can add, remove, or change text within a text view. (默认是YES)可以添加、移出、更改UITextView的text。

1、UIToolBar:

IOS7中增加UIToolbarDelegate,当UIToolbar呈现时候回调此方法:

看代码:

- (void)viewDidLoad

{

[superviewDidLoad];

UIToolbar *toolbar = [[UIToolbaralloc]initWithFrame:CGRectMake(0,20,320,44)];

toolbar.barStyle = UIBarStyleBlack;

toolbar.delegate = self;

UIBarButtonItem *item = [[UIBarButtonItemalloc]initWithTitle:@"Text"style:UIBarButtonItemStyleBorderedtarget:nilaction:nil];

[toolbar setItems:[NSArrayarrayWithObjects:item,nil]];

[self.view addSubview:toolbar];

}

/* Implement this method on your manual bar delegate when not managed by a UIKit controller.

UINavigationBar and UISearchBar default to UIBarPositionTop, UIToolbar defaults to UIBarPositionBottom.

This message will be sent when the bar moves to a window.

*/

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar

{

NSLog(@"positionForBar");

returnUIBarPositionTop;

}

设置ToolBar上边沿的阴影:

/* Default is nil. When non-nil, a custom shadow image to show instead of the default shadow image. For a custom shadow to be shown, a custom background image must also be set with -setBackgroundImage:forToolbarPosition:barMetrics: (if the default background image is used, the default shadow image will be used).
 */
- (void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIBarPosition)topOrBottom NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
- (UIImage *)shadowImageForToolbarPosition:(UIBarPosition)topOrBottom NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;

IOS7开发~新UI学起(三)的更多相关文章

  1. IOS7开发~新UI学起(一)

    本文转载至:http://blog.csdn.net/lizhongfu2013/article/details/9124893 IOS7在UI方面发生了很大改变,所以感觉有必要重新审视的学习一下(新 ...

  2. IOS7开发~新UI学起(四)

    本文转载至 http://blog.csdn.net/lizhongfu2013/article/details/9166193 1.UITableView: UITableViewDelegate ...

  3. IOS7开发~新UI学起(二)

    本文转载至 http://blog.csdn.net/lizhongfu2013/article/details/9133281 1.UINavigationBar: NSDictionary* at ...

  4. iOS开发~UI布局(三)深入理解autolayout

    一.概要 通过对iOS8界面布局的学习和总结,发现autolayout才是主角,autolayout是iOS6引入的新特性,当时还粗浅的学习了下,可是没有真正应用到项目中.随着iOS设备尺寸逐渐碎片化 ...

  5. IOS7学习之路一(新UI之自定义UITableViewCell)

    ios7 新升级之后界面有了很大的变化,xcode模拟器去掉了手机边框和home键,如果想回到主页面,可以按住shift+comment+r键.废话少说先展示一下新UI下UItableView设置为G ...

  6. UGUI的优点新UI系统三效率高效果好

    UGUI的优点新UI系统三效率高效果好 通过对批处理(batching).纹理图集(texture atlasing)和新的canvas组件的支持,新UI系统提供了一个经过优化的解决方案,使得开发者添 ...

  7. UGUI的优点新UI系统

    UGUI的优点新UI系统 第1章  新UI系统概述 UGUI的优点新UI系统,新的UI系统相较于旧的UI系统而言,是一个巨大的飞跃!有过旧UI系统使用体验的开发者,大部分都对它没有任何好感,以至于在过 ...

  8. 开发者所需要知道的iOS7 SDK新特性

    iOS 7 春风又绿加州岸,物是人非又一年.WWDC 2013 keynote落下帷幕,新的iOS开发旅程也由此开启.在iOS7界面重大变革的背后,开发者们需要知道的又有哪些呢.同去年一样,我会先简单 ...

  9. 游戏UI框架设计(三) : 窗体的层级管理

    游戏UI框架设计(三) ---窗体的层级管理 UI框架中UI窗体的"层级管理",最核心的问题是如何进行窗体的显示管理.窗体(预设)的显示我们前面定义了三种类型: 普通.隐藏其他.反 ...

随机推荐

  1. CentOS 6.3下Samba服务器的安装与配置(转)

    一.简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,而SMB是Server Message Block的缩写,即为服务器消息块 ,SMB主要是作为Microsoft的 ...

  2. Linux命令-权限管理命令:chmod

    特别注意:在linux中,目录通常是有r和x两个权限的.删除文件的前题是要对文件所在的目录有w的权限才可以. cd /tmp 切换到tmp目录下面 touch chengshi.list 在当前目录中 ...

  3. BAT解密:互联网技术发展之路(5)- 开发层技术剖析

    BAT解密:互联网技术发展之路(5)- 开发层技术剖析 1. 开发框架 在系列文章的第2篇"BAT解密:互联网技术发展之路(2)- 业务怎样驱动技术发展"中我们深入分析了互联网业务 ...

  4. php 实现打印预览的功能

    <inputid="btnPrint" type="button" value="打印"onclick="javascrip ...

  5. [转]html5调用摄像头实例

    原文:https://blog.csdn.net/binquan_liang/article/details/79489989 最近在学习在做HTML5的项目,看了博客上html5调用摄像头拍照的文章 ...

  6. LINK : fatal error LNK1104

    今天本来想试试opencv的,于是就在自己的机子上部署一下试试,结果一直遇到这个错误:LINK : fatal error LNK1104 环境:win7 64位 vs2012 opencv 2.4. ...

  7. ftok函数例子

    #include <stdio.h>#include <sys/types.h>#include <sys/ipc.h>int main( void ){ int ...

  8. rt serial 的编写

    /* * Copyright (C) 2005-2007 Jan Kiszka <jan.kiszka@web.de>. * * Xenomai is free software; you ...

  9. PHP——数组中的each(),list()和while循环遍历数组

    .while遍历 在while()语句每次循环中,each()语句将当前数组元素的键,赋给list()函数的第一个参数变量$key.并将当前数组元素中的值,赋给list()函数中的第二个参数变量$va ...

  10. phpadmin 装了6666端口只能在IE打开,在阿里云改了 开放端口85好了

    phpadmin 装了6666端口只能在IE打开,在阿里云改了 开放端口85好了 非常用端口谷歌浏览器识别不了phpadmin