IOS7开发~新UI学起(三)
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学起(三)的更多相关文章
- IOS7开发~新UI学起(一)
本文转载至:http://blog.csdn.net/lizhongfu2013/article/details/9124893 IOS7在UI方面发生了很大改变,所以感觉有必要重新审视的学习一下(新 ...
- IOS7开发~新UI学起(四)
本文转载至 http://blog.csdn.net/lizhongfu2013/article/details/9166193 1.UITableView: UITableViewDelegate ...
- IOS7开发~新UI学起(二)
本文转载至 http://blog.csdn.net/lizhongfu2013/article/details/9133281 1.UINavigationBar: NSDictionary* at ...
- iOS开发~UI布局(三)深入理解autolayout
一.概要 通过对iOS8界面布局的学习和总结,发现autolayout才是主角,autolayout是iOS6引入的新特性,当时还粗浅的学习了下,可是没有真正应用到项目中.随着iOS设备尺寸逐渐碎片化 ...
- IOS7学习之路一(新UI之自定义UITableViewCell)
ios7 新升级之后界面有了很大的变化,xcode模拟器去掉了手机边框和home键,如果想回到主页面,可以按住shift+comment+r键.废话少说先展示一下新UI下UItableView设置为G ...
- UGUI的优点新UI系统三效率高效果好
UGUI的优点新UI系统三效率高效果好 通过对批处理(batching).纹理图集(texture atlasing)和新的canvas组件的支持,新UI系统提供了一个经过优化的解决方案,使得开发者添 ...
- UGUI的优点新UI系统
UGUI的优点新UI系统 第1章 新UI系统概述 UGUI的优点新UI系统,新的UI系统相较于旧的UI系统而言,是一个巨大的飞跃!有过旧UI系统使用体验的开发者,大部分都对它没有任何好感,以至于在过 ...
- 开发者所需要知道的iOS7 SDK新特性
iOS 7 春风又绿加州岸,物是人非又一年.WWDC 2013 keynote落下帷幕,新的iOS开发旅程也由此开启.在iOS7界面重大变革的背后,开发者们需要知道的又有哪些呢.同去年一样,我会先简单 ...
- 游戏UI框架设计(三) : 窗体的层级管理
游戏UI框架设计(三) ---窗体的层级管理 UI框架中UI窗体的"层级管理",最核心的问题是如何进行窗体的显示管理.窗体(预设)的显示我们前面定义了三种类型: 普通.隐藏其他.反 ...
随机推荐
- tsung 学习
tsung简介: Tsung是开源的基于Erlang语言开发的多协议分布式压力测试工具,它能用来压力测试HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP 和 ...
- Java SSL证书的安装
https正在成为主流,http估计在不久的将来会被彻底放弃…… 一个Java程序需要访问一个https的网站的时候,可能需要涉及证书的安装,卸载等操作. 一.证书的下载 打开浏览器输入https:/ ...
- ItelliJ基于Gradle创建及发布Web项目(一)
背景:安装IntelliJ,去官网下载. 创建WEB项目 1. File->New Project,在弹出的选项框中勾选Web,如下图. IntelliJ默认使用Gradle,感谢Gradle. ...
- vsftpd問題集
vsftpd无法看到文件:226 Transfer done (but failed to open directory). 原因:目录不是一个 world_readable目录 解决方法:在配置文件 ...
- atitit.D&D drag&drop拖拽文件到界面功能 html5 web 跟个java swing c#.net c++ 的总结
atitit.D&D drag&drop拖拽文件到界面功能 html5 web 跟个java swing c#.net c++ 的总结 1. DND的操作流程 1 2. Html5 注 ...
- HUD 2544 最短路 迪杰斯特拉算法
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- iOS开发之使用AFN上传图片
//1.创建管理者对象 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializ ...
- Hadoop默认端口表及用途
端口 用途 9000 fs.defaultFS,如:hdfs://172.25.40.171:9000 9001 dfs.namenode.rpc-address,DataNode会连接这个端口 ...
- Hive Compiler过程
通过Parser将HiveQL转换成AST,通过Semantic Analyzer将AST转换为QB,通过Logical Plan Generator将QB转换成Operator Tree,通过Log ...
- 基于HTML5堆木头游戏
今天要来分享一款很经典的HTML5游戏——堆木头游戏,这款游戏的玩法是将木头堆积起来,多出的部分将被切除,直到下一根木头无法堆放为止.这款HTML5游戏的难点在于待堆放的木头是移动的,因此需要你很好的 ...