IOS中UITextView控件的一些使用方法
2012-11-27 11:38
381 查看
转 原文http://www.jizhishusheng.com/?p=446
1、设置UITextView的属性
textView.returnKeyType = UIReturnKeyDefault;//返回键的类型
textView.keyboardType = UIKeyboardTypeDefault;//键盘类型
textView.scrollEnabled = YES;//是否可以拖动
textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度
2、设置UITextView圆角问题
先引入#import <QuartzCore/QuartzCore.h>
textView.layer.cornerRadius = 8; //给图层的边框设置为圆角
textView.layer.masksToBounds = YES;
3、给TextView加一个有色边框,并设置背景图片
//给图层添加一个有色边框
textView.layer.borderWidth = 5;
textView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:0.5] CGColor];
textView.layer.contents = (id)[UIImage imageNamed:@"xxxxx"].CGImage; //给图层添加背景图片
4、UITextView自定选择文字后的菜单 在ViewDidLoad中加入:
- (void)viewDidLoad {
[super viewDidLoad];
self._textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 100, 300, 200)];//初始化
_textView.font = [UIFont fontWithName:@"Arial" size:33];//设置字体名字和字体大小
[self.view addSubview:_textView];
UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"分享到新浪微博" action:@selector(fun)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObject:menuItem]];
[menuItem release]; }
@selector里面的fun方法是自己写的函数,也就是说点击了我们自定义的菜单项后会触发的方法。 然后还得在代码里加上一个方法:
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if(action==@selector(changeColor) || action == @selector(copy:))
{
if(_textView.selectedRange.length>0)
return YES;
} return NO; }
-(void) fun {
NSLog(@"%@",[_textView.text substringWithRange:_textView.selectedRange]);
}
1、设置UITextView的属性
textView.returnKeyType = UIReturnKeyDefault;//返回键的类型
textView.keyboardType = UIKeyboardTypeDefault;//键盘类型
textView.scrollEnabled = YES;//是否可以拖动
textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度
2、设置UITextView圆角问题
先引入#import <QuartzCore/QuartzCore.h>
textView.layer.cornerRadius = 8; //给图层的边框设置为圆角
textView.layer.masksToBounds = YES;
3、给TextView加一个有色边框,并设置背景图片
//给图层添加一个有色边框
textView.layer.borderWidth = 5;
textView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:0.5] CGColor];
textView.layer.contents = (id)[UIImage imageNamed:@"xxxxx"].CGImage; //给图层添加背景图片
4、UITextView自定选择文字后的菜单 在ViewDidLoad中加入:
- (void)viewDidLoad {
[super viewDidLoad];
self._textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 100, 300, 200)];//初始化
_textView.font = [UIFont fontWithName:@"Arial" size:33];//设置字体名字和字体大小
[self.view addSubview:_textView];
UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"分享到新浪微博" action:@selector(fun)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObject:menuItem]];
[menuItem release]; }
@selector里面的fun方法是自己写的函数,也就是说点击了我们自定义的菜单项后会触发的方法。 然后还得在代码里加上一个方法:
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if(action==@selector(changeColor) || action == @selector(copy:))
{
if(_textView.selectedRange.length>0)
return YES;
} return NO; }
-(void) fun {
NSLog(@"%@",[_textView.text substringWithRange:_textView.selectedRange]);
}
相关文章推荐
- IOS中UITextView控件的一些使用方法
- IOS中UITextView控件的一些使用方法
- IOS 学习笔记(5) 控件 文本视图(UITextView)的使用方法
- IOS 学习笔记(7) 控件 分隔栏控件(UISegmentControl)的使用方法
- 关于ios的autoLayout的一些简单介绍以及使用方法
- [置顶]对FileUpload文件上传控件的一些使用方法说明
- IOS的基本控件的使用-UITextView(单行文本输入区域)
- iOS --- block的一些使用方法(反向传值)
- ios学习之UI控件的一些基本使用
- IE 控件一些高级使用方法
- iOS学习之UISwitch控件两种使用方法和监听
- iOS选择器视图控件(UIPickerView)使用方法总结
- iOS 常用控件的使用方法
- 关于ios的autoLayout的一些简单介绍以及使用方法
- IOS--UITextView 多行文本的输入和显示 的使用方法详细
- ios控件中方法使用
- VC 中一些控件的使用方法(TabControl, 工具栏)
- ios 使用UINavagationController时,push,pop方法执行的一些方法 - shidaying
- iOS:文本视图控件UITextView的详细使用
- IOS学习之UISwitch控件两种使用方法和监听