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属性设置的更多相关文章

  1. IOS 导航栏属性设置

    IOS 7 以上系统导航栏: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // 返回按钮颜色 [UINaviga ...

  2. IOS 常用View属性设置

    设置按钮属性 1.设置按钮背景颜色 backgroundColor @property (weak, nonatomic) IBOutlet UIButton *deleteButton; self. ...

  3. Android textAppearance的属性设置及TextView属性详解

    textAppearance的属性设置 android:textAppearance="?android:attr/textAppearanceSmall" android:tex ...

  4. ios变量的property属性设置和意义

    IOS 的@property和@synthesize帮我们轻易的生成对象的getter和setter方法来完成对对象的赋值和访问.但是如果我们如果要动态设置对象的getter和setter方法可以使用 ...

  5. 简单分析android textview xml 的属性设置

    android:ems 设置TextView的宽度为N个字符的宽度. 这样的好处就是,在定义编辑框空间输入多少字符的时候,可以根据固定的值设置编辑框宽度.保证边框和文字的宽度统一.android:ma ...

  6. Android中TextView和EditView经常使用属性设置

    Android开发中最经常使用的几乎相同就是TextView和EditView了,在使用它时.我们也会设置它的一些属性,为了让我们设计的更好看,设置的更合理.这里记下它的经常使用属性,方便后期查阅. ...

  7. iOS开发笔记--UILabel的相关属性设置

    在iOS编程中UILabel是一个常用的控件,下面分享一下UILabel的相关属性设置的方法. 很多学习iOS6编程都是从storyboard开始,用到UILabel时是将控件拖到storyboard ...

  8. Android中TextView和EditView常用属性设置

    Android中TextView和EditView常用属性设置 点击跳转

  9. TextView属性android:ellipsize="marquee"不生效的解决办法

    最近自己在写自己的第一个app,过程中遇到了这个问题,查了不少帖子,经过尝试发现,这种问题一般分为两类: 1. TextView的Text值赋值后不更改,很多帖子上说如下写法就可以生效: <Te ...

随机推荐

  1. saltstack master minion安装配置简单使用

    首先先了解下saltstack是什么,为什么使用它 它与Ansible.Puppet都属于集中管理工具,由于现在企业规模的不断庞大及业务的增长,所需要管理的服务器数量增多,而且大部分机器都属于同类业务 ...

  2. 【Hive】Hive笔记:Hive调优总结——数据倾斜,join表连接优化

    数据倾斜即为数据在节点上分布不均,是常见的优化过程中常见的需要解决的问题.常见的Hive调优的方法:列剪裁.Map Join操作. Group By操作.合并小文件. 一.表现 1.任务进度长度为99 ...

  3. 第一节:Java 语言基础

    5分30开始 18分正式开始议题 23分01开始创建项目: 讲个面向过程,函数式的方式 byte(8) char(16) short(16) int(32) long(64) long类型或者doub ...

  4. 洛谷 - P1593 - 因子和 - 费马小定理

    类似的因为模数比较小的坑还有卢卡斯定理那道,也是有时候逆元会不存在,因为整除了.使用一些其他方法避免通过逆元. https://www.luogu.org/fe/problem/P1593 有坑.一定 ...

  5. HDU3555【数位DP】

    入门...还在学习中,先贴一发大牛博客 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意: 给一个数字n,范围在1~2^63-1,求1~ ...

  6. 3D游戏中人物换装解决方案

    换装基本上是每个网游都必须有的一个功能,每种网游的做法都各有不同,有些是换掉整个模型,有些则是通过可以换掉模型的一个部分完成.前者属于整体换,相对简单些:后者则是通过部分替换实现,目前用的比较多,本文 ...

  7. AFN的使用

    http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...

  8. JDK1.7 和 jetty配置教程

    系统是windows 7 64位版本,32位版本同理,xp系统的自己google设置环境变量 打开设置环境变量窗口,右键计算机->我的电脑,选择属性 点击高级系统设置 选择环境变量 红线为需要设 ...

  9. 【TeamViewer】v13.2.26558版本 修改ID

    TeamViewer是一款远程协作软件,可以让你在一台机器上操作另一台机器.比如我最近就经常在家里连接公司的电脑进行远程工作.可以说是对于程序员很好用的一个软件. TeamViewer 使用频繁后会被 ...

  10. bzoj1145[CTSC2008]图腾

    传送门 虽然是远古时期的ctsc,但是果然还是ctsc啊 前置芝士:树状数组 这个题最开始的思路很好想,由于之前写过一个类似处理的题,所以这个题我一开始就想到了思路. 首先,我们可以尝试讲图腾表示为x ...