IOS之TextView属性设置
UIFontDescriptor *bodyFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody]; |
self.textView.font = [UIFont fontWithDescriptor:bodyFontDescriptor size:0]; |
self.textView.textColor = [UIColor blackColor]; |
self.textView.backgroundColor = [UIColor whiteColor]; |
self.textView.scrollEnabled = YES; |
// Let's modify some of the attributes of the attributed string. |
// You can modify these attributes yourself to get a better feel for what they do. |
// Note that the initial text is visible in the storyboard. |
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.textView.attributedText]; |
NSString *text = self.textView.text; |
// Find the range of each element to modify. |
NSRange boldRange = [text rangeOfString:NSLocalizedString(@"bold", nil)]; |
NSRange highlightedRange = [text rangeOfString:NSLocalizedString(@"highlighted", nil)]; |
NSRange underlinedRange = [text rangeOfString:NSLocalizedString(@"underlined", nil)]; |
NSRange tintedRange = [text rangeOfString:NSLocalizedString(@"tinted", nil)]; |
// Add bold. |
UIFontDescriptor *boldFontDescriptor = [self.textView.font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; |
UIFont *boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size:0]; |
[attributedText addAttribute:NSFontAttributeName value:boldFont range:boldRange]; |
// Add highlight. |
[attributedText addAttribute:NSBackgroundColorAttributeName value:[UIColor aapl_applicationGreenColor] range:highlightedRange]; |
// Add underline. |
[attributedText addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:underlinedRange]; |
// Add tint. |
[attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor aapl_applicationBlueColor] range:tintedRange]; |
// Add an image attachment. |
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init]; |
UIImage *image = [UIImage imageNamed:@"text_view_attachment"]; |
textAttachment.image = image; |
textAttachment.bounds = CGRectMake(0, 0, image.size.width, image.size.height); |
NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment]; |
[attributedText appendAttributedString:textAttachmentString]; |
self.textView.attributedText = attributedText; |
IOS之TextView属性设置的更多相关文章
- IOS 导航栏属性设置
IOS 7 以上系统导航栏: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // 返回按钮颜色 [UINaviga ...
- IOS 常用View属性设置
设置按钮属性 1.设置按钮背景颜色 backgroundColor @property (weak, nonatomic) IBOutlet UIButton *deleteButton; self. ...
- Android textAppearance的属性设置及TextView属性详解
textAppearance的属性设置 android:textAppearance="?android:attr/textAppearanceSmall" android:tex ...
- ios变量的property属性设置和意义
IOS 的@property和@synthesize帮我们轻易的生成对象的getter和setter方法来完成对对象的赋值和访问.但是如果我们如果要动态设置对象的getter和setter方法可以使用 ...
- 简单分析android textview xml 的属性设置
android:ems 设置TextView的宽度为N个字符的宽度. 这样的好处就是,在定义编辑框空间输入多少字符的时候,可以根据固定的值设置编辑框宽度.保证边框和文字的宽度统一.android:ma ...
- Android中TextView和EditView经常使用属性设置
Android开发中最经常使用的几乎相同就是TextView和EditView了,在使用它时.我们也会设置它的一些属性,为了让我们设计的更好看,设置的更合理.这里记下它的经常使用属性,方便后期查阅. ...
- iOS开发笔记--UILabel的相关属性设置
在iOS编程中UILabel是一个常用的控件,下面分享一下UILabel的相关属性设置的方法. 很多学习iOS6编程都是从storyboard开始,用到UILabel时是将控件拖到storyboard ...
- Android中TextView和EditView常用属性设置
Android中TextView和EditView常用属性设置 点击跳转
- TextView属性android:ellipsize="marquee"不生效的解决办法
最近自己在写自己的第一个app,过程中遇到了这个问题,查了不少帖子,经过尝试发现,这种问题一般分为两类: 1. TextView的Text值赋值后不更改,很多帖子上说如下写法就可以生效: <Te ...
随机推荐
- SIP呼叫流程典型流程图解及其详细解释
目录(?)[+] 1.注册流程: 2.注销流程: 3. 基本呼叫建立过程: 4. 会话更改流程: 5. 正常呼叫释放过程: 6. 被叫忙呼叫释放: 7.被叫无应答流程一: 8.被叫无应答流程二: ...
- Spark Streaming之二:StreamingContext解析
1.1 创建StreamingContext对象 1.1.1通过SparkContext创建 源码如下: def this(sparkContext: SparkContext, batchDurat ...
- py-day2-sys模块、os模块、运算符、列表、字典
一.sys 模块 import sys print (sys.path)#打印环境变量 print(sys.aegv) #打印脚本的名字相对路径 print(sys.aegv)1 2 3 4 prin ...
- rpm 命令|rpm 安装|rpm 卸载|rpm 使用|rpm 删除
在Linux操作系统中,有一个系统软件包,它的功能类似于Windows里面的“添加/删除程序”,但是功能又比“添加/删除程序”强很多,它就是Red Hat Package Manager(简称RPM) ...
- 使用JavaScript选择GridView行的方法汇总
一行: e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvUsers, &q ...
- SmartSql使用教程(3)——SmartSql中的事务,及AOP的使用
一.引言 经过两章的铺垫,我们现在对SmartSql已经有了一定的了解,那么今天我们的主题是事务处理.事务处理是常用的一种特性,而SmartSql至少提供了两种使用事务的方法.一种是通过Reposit ...
- meta标签常用属性
Keywords(关键词) 说明:告诉搜索引擎你网页的关键字(keywords)使用方法:<meta name="keywords" content="标签,属性, ...
- 洛谷P4717 【模板】快速沃尔什变换(FWT)
传送门 这玩意儿太骚了…… 参考了yyb巨佬的 //minamoto #include<iostream> #include<cstdio> #define ll long l ...
- 转 Vlan
1.支持VLAN的交换机一定是三层交换机吗?2.Trunk配置了就可以VLAN间通信吗?3.Trunk具体怎么工作的?4.VLAN间的通信到底是怎么执行的?如果说给若干个纯二层环境加上若干个路由器,我 ...
- RecyclerView notifyDataSetChanged无效问题
使用notifyDataSetChanged方法更新列表数据时, 一定要保证数据为同个对象(hashCode要一致) 所以重新刷新数据列表时, 不能使用 List list = mlist: 应该使用 ...