直接上代码:

//
// RootViewController.m
// UIText_test
//
// #import "RootViewController.h"
#import <QuartzCore/QuartzCore.h> /// 用户视觉反馈 @interface RootViewController ()<UITextViewDelegate> @property (nonatomic, strong) UIToolbar *toolBar ;
@property (nonatomic, strong) UITextView *textView ; @end @implementation RootViewController - (UIToolbar *)toolBar {
if (!_toolBar) {
self.toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 375, 30)];
[_toolBar setBarStyle:UIBarStyleBlack];
UIBarButtonItem *oneButton = [[UIBarButtonItem alloc] initWithTitle:@"開始" style:UIBarButtonItemStyleDone target:self action:nil]; UIBarButtonItem *twoButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil]; UIBarButtonItem *threeButton = [[UIBarButtonItem alloc] initWithTitle:@"完毕" style:UIBarButtonItemStyleDone target:self action:@selector(handleThreeBtn)]; NSArray *buttonArray = [NSArray arrayWithObjects:oneButton, twoButton, threeButton, nil];
[_toolBar setItems:buttonArray]; // 加入到 toolBar 上
}
return _toolBar;
} - (UITextView *)textView {
if (!_textView) {
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(5, 200, 375, 190)];
_textView.textColor = [UIColor redColor];
_textView.font = [UIFont systemFontOfSize:20];
_textView.delegate = self;
[_textView.layer setCornerRadius:10]; // 设置成圆角
_textView.backgroundColor = [UIColor cyanColor];
_textView.text = @"sfjlegjklaeyg a";
_textView.scrollEnabled = YES;
_textView.autoresizingMask = UIViewAutoresizingFlexibleHeight ; // 自适应高度
[_textView setInputAccessoryView:self.toolBar]; // 设置辅助视图
}
return _textView;
} - (void)viewDidLoad {
[super viewDidLoad]; [self.view addSubview:self.textView]; // 自己定义菜单项
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"分享到新浪微博" action:@selector(changeColor)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObject:menuItem]]; //加入
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - Action - - (void)handleThreeBtn {
[self.textView resignFirstResponder]; // 撤销第一次响应
} - (void)changeColor {
self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1];
} - (void)handleDone {
[self.textView resignFirstResponder]; // 撤销第一响应
} #pragma mark - UITextViewDelegate - // 完毕開始编辑
- (void)textViewDidBeginEditing:(UITextView *)textView {
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(handleDone)];
self.navigationItem.rightBarButtonItem = done;
} // 完毕结束编辑
- (void)textViewDidEndEditing:(UITextView *)textView {
self.navigationItem.rightBarButtonItem = nil; /// 导航条按钮设置为空
} // 当文本发生改变时
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ([text isEqual:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
} @end

UITextView 的使用的更多相关文章

  1. UITextView 输入字数限制

    本文介绍了UITextView对中英文还有iOS自带表情输入的字数限制,由于中文输入会有联想导致字数限制不准确所以苦恼好久,所以参考一些大神的博客终于搞定,欢迎大家参考和指正. 对于限制UITextV ...

  2. iOS 之UITextFiled/UITextView小结

    一:编辑被键盘遮挡的问题 参考自:http://blog.csdn.net/windkisshao/article/details/21398521 1.自定方法 ,用于移动视图 -(void)mov ...

  3. UITextView 点击添加文字 光标处于最后方

    #import "ViewController.h" @interface ViewController ()<UITextViewDelegate> @end @im ...

  4. UI控件(UITextView)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //UITextView与UITextField主要 ...

  5. 实现UITextView的placeholder

    我们知道在iOS开发时,控件UITextField有个placeholder属性,UITextField和UITextView使用方法基本类似,有两个小区别:1.UITextField单行输入,而UI ...

  6. UITextView回收或关闭键盘

    iOS开发中,发现UITextView没有像UITextField中textFieldShouldReturn:这样的方法,那么要实现UITextView关闭键盘,就必须使用其他的方法,下面是可以使用 ...

  7. [转]iOS7中UITextView contentsize改变时机

    在iOS7以下版本中,对UITextView设置了text属性,则contentsize就会变化,从而可以根据contentsize的变化来改变UITextView高度来做出TextView高度随着输 ...

  8. UITextView 显示不全的问题

    //设置UITextView的内边距 textView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);

  9. UITextView: 响应键盘的 return 事件(收回键盘)

    UITextView: 响应键盘的 return 事件(收回键盘) 此篇文章将要介绍UITextView: 响应键盘的 return 事件(收回键盘)的相关介绍,具体实例请看下文 UITextView ...

  10. 你真的了解UITextView吗?

    一:首先查看一下关于UITextView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextView : UIScrollView <UITextI ...

随机推荐

  1. liblinear参数及使用方法(原创)

    开发语言:JAVA 开发工具:eclipse (下载地址 http://www.eclipse.org/downloads/) liblinear版本:liblinear-1.94.jar (下载地址 ...

  2. USACO 2017 FEB Gold visitfj 最短路

    题意 有一幅n*n的方格图,n <= 100,每个点上有一个值.从(1,1)出发,走到(n,n),只能走四联通.每走一步花费t,每走三步需要花费走完三步后到达格子的值.求最小花费的值. 拆点,d ...

  3. iOS Contact框架功能研究

    兄弟们,直接复制,感谢度娘,感谢谷哥!!! 1.读取联系人通讯录 /** *  读取联系人通讯录 */ -(NSMutableArray*)getContactList{ NSMutableArray ...

  4. BZOJ 1032 JSOI 2007 祖码Zuma 区间DP

    题目大意:依照祖玛的玩法(任意选颜色),给出一段区间.问最少用多少个球可以把全部颜色块都消除. 思路:把输入数据依照连续的块处理.保存成颜色和数量.然后用这个来DP.我们知道,一个单独的块须要两个同样 ...

  5. 几个未公开的 DBCC 命令

    http://blog.csdn.net/CathySun118/article/category/538610 https://ask.hellobi.com/blog/lyhabc/1612 1. ...

  6. 探究rh6上mysql5.6的主从、半同步、GTID多线程、SSL认证主从复制

    http://407711169.blog.51cto.com/6616996/1203973/

  7. ou have not concluded your merge (MERGE_HEAD exists)

    今天获取git线上仓库代码报了这个错误: zhangzhi@moke:~/code/ktsg-api$ git pull You have not concluded your merge (MERG ...

  8. rt-80启动tomcat

    1 #!/bin/sh 2 cd /mnt/tomcat/tomcat_8082; 3 ps -ef|grep /tomcat_8082/ |awk '{print $2}'|xargs kill - ...

  9. NAT详解 z

    http://www.cnblogs.com/beginmind/p/6380489.html 1.为什么出现了NAT? IP地址只有32位,最多只有42.9亿个地址,还要去掉保留地址.组播地址,能用 ...

  10. 如何从MATLAB里面保存出分辨率高的图形

    MATLAB堪称科技工作者的倚天屠龙,其科学计算,简洁的编程风格,友好的图形界面等等,都使得它颇受欢迎.MATLAB作图相当简单,而且美观,但是,缺点是分辨率低,一直没有发现,直到最近一期刊编辑告诉我 ...