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 ...
随机推荐
- socket辅助类
using System; using System.Collections; using System.Net; using System.Net.Sockets; using System.Tex ...
- zz 堆空间与栈空间
http://blog.sina.com.cn/s/blog_7321be1101013aua.htmlhttp://soft.chinabyte.com/os/51/12324551.shtmlht ...
- python 之队列
进程和线程模块下都有队列类. 线程队列: # 后进先出->堆栈 q=queue.LifoQueue(3) # 优先级队列,数字越小优先级越高 q=queue.PriorityQueue(3) 进 ...
- Flutter实战视频-移动电商-37.路由_Fluro引入和商品详细页建立
37.路由_Fluro引入和商品详细页建立 https://github.com/theyakka/fluro pages/details_page.dart新建页面 使用路由 先添加路由插件的引用 ...
- 使用SQL访问MongoDB
使用SQL访问MongoDB 简介 使用SQL访问MongoDB有多种解决方案,就我所知的,除了今天要介绍的MongoDB Connector for BI外,还有Studio 3T,但后者只有在企业 ...
- python---socket与socketserver
1.socket的方socket.getaddrinfo(host, port, family=0, type=0, proto=0, flags=0) #获取要连接的对端主机地址sk.bind(ad ...
- 甩掉DataList,Repeater,列表数据显示得灵活--转
在WebForm 显示列表数据我们一般使用服务器控件Repeater.DataList或者GridView ,功强大能,使用简单.但同时也是有代价的, 一:不管你用哪个控件都需要牺牲一些额外的性能,因 ...
- 《剑指offer》面试题1:为类CMyString添加赋值运算符函数——C++拷贝构造函数与赋值函数
题中已给出CMyString的类定义,要求写赋值运算符函数. #include<iostream> #include<cstring> using namespace std; ...
- 线程通讯--BlockingQueue
Producer线程 package com.thread.communication.blockingqueue; import java.util.concurrent.BlockingQueue ...
- Linux文件IO操作函数概述
文件概述 Linux中,一切皆文件.文件为操作系统服务和设备提供了一个简单而一致的接口.这意味着程序完全可以像使用文件那样使用磁盘文件.串行口.打印机和其他设备. 也就是说,大多数情况下,你只需要使用 ...