UITextView 详解
#import <QuartzCore/QuartzCore.h>
textView.layer.borderColor = [UIColor grayColor].CGColor;
textView.layer.borderWidth =1.0;
textView.layer.cornerRadius =5.0;
建立一个UITextView,默认启动键盘,并将光标定位到首位置,因为UITextFiled类没有此功能,所以改用UItextView.
代码如下:
Cpp代码
UITextView *m_contentTextField = [[[UITextView alloc] init] autorelease];
m_contentTextField = [[[UITextView alloc] init] autorelease];
m_contentTextField.frame = CGRectMake(, , , ) ;
m_contentTextField.backgroundColor = [UIColor whiteColor] ;
m_contentTextField.font = [UIFont systemFontOfSize:];
m_contentTextField.delegate = self ;
设置此UITextView为第一响应者,即默认打开键盘。
Cpp代码
[m_contentTextField becomeFirstResponder];
当UITextView中含有文字时,系统默认将光标定位到最后的位置,下面的语句将光标定位到首位置。
Cpp代码
m_contentTextField.selectedRange = NSMakeRange(,); 参考文献:https://discussions.apple.com/message/12209784#12209784
iOS:个性化UITextView(缩进,行距,铺满)(点击可进,已试用,可行)
总体来说个性化定制UITextView中的内容有两种方法:
,从文件中读取内容到UITextView,这个个人感觉使用rtfd和rtf格式文件效果非常好。 ,使用NSAttributeString进行定制 具体方法如下: NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineHeightMultiple = .f;
paragraphStyle.maximumLineHeight = .f;
paragraphStyle.minimumLineHeight = .f;
paragraphStyle.firstLineHeadIndent = .f;
paragraphStyle.alignment = NSTextAlignmentJustified; NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:], NSParagraphStyleAttributeName:paragraphStyle, NSForegroundColorAttributeName:[UIColor colorWithRed:./. green:./. blue:./. alpha:]
};
textView.attributedText = [[NSAttributedString alloc]initWithString:content attributes:attributes]; 当然也可以初始化一个NSMutableAttributedString,然后向里面添加文字样式,最后将它赋给textView的AttributedText即可 NSMutableAttributedString *atr = [[NSMutableAttributedString alloc]initWithString:detail];
[atr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:] range:NSMakeRange(, detail.length)];
textView.attributedText = atr; 另外,对于textview中的链接样式,同样也可以定制 NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],
NSUnderlineColorAttributeName: [UIColor blackColor],
NSUnderlineStyleAttributeName: @(NSUnderlinePatternDash)};
self.linkTextAttributes = linkAttributes; 这里只是个简单的例子,具体还有很多属性可以自行参考头文件
UITextView 文本换行
从XML或者json中读取出来的"\n",系统认为是字符串,会默认转换为"\\n",所以当显示的时候就是字符串了,要想显示换行,需要自己手动将"\\n"转换为"\n",这样才能换行.
NSString*b =[a stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
设置显示内容的padding
textView.textContainerInset = UIEdgeInsetsMake(0, 10, 0, 10);
效果是右侧的滚动条距离内容10像素
参考:How to set margins (padding) in UITextView?

UITextView 详解的更多相关文章
- UITextView详解
self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease]; //初始化大小并自动释放 sel ...
- UITextView的使用详解
//初始化并定义大小 UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 30)]; te ...
- 【转】UITextView的使用详解
//初始化并定义大小 UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 30)]; te ...
- 【iOS 开发】基本 UI 控件详解 (UIButton | UITextField | UITextView | UISwitch)
博客地址 : http://blog.csdn.net/shulianghan/article/details/50051499 ; 一. UI 控件简介 1. UI 控件分类 UI 控件分类 : 活 ...
- iOS中 HTTP/Socket/TCP/IP通信协议详解
// OSI(开放式系统互联), 由ISO(国际化标准组织)制定 // 1. 应用层 // 2. 表示层 // 3. 会话层 // 4. 传输层 // 5. 网络层 // 6. 数据链接层 // 7. ...
- iOS应用开发详解
<iOS应用开发详解> 基本信息 作者: 郭宏志 出版社:电子工业出版社 ISBN:9787121207075 上架时间:2013-6-28 出版日期:2013 年7月 开本:16开 ...
- IOS 触摸事件分发机制详解
欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 作者:MelonTeam 前言 很多时候大家都不关心IOS触摸事件的分发机制的实现原理,当遇到以下几种情形的时候你很可能抓破头皮都找不到解决方案 ...
- iOS中 HTTP/Socket/TCP/IP通信协议详解 韩俊强的博客
每日更新关注:http://weibo.com/hanjunqiang 新浪微博 简单介绍: // OSI(开放式系统互联), 由ISO(国际化标准组织)制定 // 1. 应用层 // 2. 表示层 ...
- iOS学习——(转)UIResponder详解
本文转载自:ios开发 之 UIResponder详解 我们知道UIResponder是所有视图View的基类,在iOS中UIResponder类是专门用来响应用户的操作处理各种事件的,包括触摸事件( ...
随机推荐
- centos下安装zabbix
1. 安装mysql CREATE DATABASE zabbix;GRANT ALL ON zabbix.* TO 'zabbix'@'192.168.19.%' IDENTIFIED BY '12 ...
- HDU - 5136 2014icpc南京现场赛J 计数dp
题目大意:给你一个树的直径k,要求每个点的度数不超过3, 问你有多少棵树满足条件. 思路:好难啊. 主要思想就是将一棵无根二叉树树划分成有根二叉树. 我们对k的分奇偶讨论: 我们定义dp[ i ] 为 ...
- LogStash plugins-inputs-file介绍(三)
官方文档 https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html 重要参数: path # 文件路径 sin ...
- 备份恢复-----system表空间损坏
无法进行关库,报错如下 SQL> shutdown immediate ORA-01122: database file 1 failed verification checkORA-01110 ...
- win7下docker环境搭建nginx+php-fpm+easyswoole开发环境
基础的环境已在文章nginx.php-fpm.swoole HTTP/TCP压测对比中搭建了,现在是在这个基础上在搭建easyswoole开发环境 主要要修改的地方是dnmp包里面的docker-co ...
- poj1979 Red And Black(DFS)
题目链接 http://poj.org/problem?id=1979 思路 floodfill问题,使用dfs解决 代码 #include <iostream> #include < ...
- Adobe Photoshop CC 2017-18.0安装教程
Adobe Photoshop CC 2017-18.0安装教程 注:下载链接在文章后面 第一步:首先请将电脑的网络断开,很简单:禁用本地连接或者拔掉网线,这样就可以免除登录Creative Clou ...
- CSUOJ 1162 Balls in the Boxes 快速幂
Description Mr. Mindless has many balls and many boxes,he wants to put all the balls into some of th ...
- UVA - 10815 - Andy's First Dictionary STL
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him ...
- 【BZOJ 2724】 2724: [Violet 6]蒲公英 (区间众数不带修改版本)
2724: [Violet 6]蒲公英 Time Limit: 40 Sec Memory Limit: 512 MBSubmit: 1908 Solved: 678 Description In ...