1. UIFontDescriptor *bodyFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
  1. self.textView.font = [UIFont fontWithDescriptor:bodyFontDescriptor size:0];
 
  1. self.textView.textColor = [UIColor blackColor];
  1. self.textView.backgroundColor = [UIColor whiteColor];
  1. self.textView.scrollEnabled = YES;
 
  1. // Let's modify some of the attributes of the attributed string.
  1. // You can modify these attributes yourself to get a better feel for what they do.
  1. // Note that the initial text is visible in the storyboard.
  1. NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.textView.attributedText];
 
  1. NSString *text = self.textView.text;
 
  1. // Find the range of each element to modify.
  1. NSRange boldRange = [text rangeOfString:NSLocalizedString(@"bold", nil)];
  1. NSRange highlightedRange = [text rangeOfString:NSLocalizedString(@"highlighted", nil)];
  1. NSRange underlinedRange = [text rangeOfString:NSLocalizedString(@"underlined", nil)];
  1. NSRange tintedRange = [text rangeOfString:NSLocalizedString(@"tinted", nil)];
 
  1. // Add bold.
  1. UIFontDescriptor *boldFontDescriptor = [self.textView.font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
  1. UIFont *boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size:0];
  1. [attributedText addAttribute:NSFontAttributeName value:boldFont range:boldRange];
 
  1. // Add highlight.
  1. [attributedText addAttribute:NSBackgroundColorAttributeName value:[UIColor aapl_applicationGreenColor] range:highlightedRange];
 
  1. // Add underline.
  1. [attributedText addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:underlinedRange];
 
  1. // Add tint.
  1. [attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor aapl_applicationBlueColor] range:tintedRange];
 
  1. // Add an image attachment.
  1. NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
  1. UIImage *image = [UIImage imageNamed:@"text_view_attachment"];
  1. textAttachment.image = image;
  1. textAttachment.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
 
  1. NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
  1. [attributedText appendAttributedString:textAttachmentString];
 
  1. 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. HDU1496(巧妙hash)

    Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. visualstudio2017 +EF+Mysql生成实体数据模型闪退

    VisualStudio2017+EF+MySql正常运转,费了不少劲,踏过不少坑 1.安装 Connector/NET 8.0.13 地址:https://dev.mysql.com/downloa ...

  3. bzoj4892

    后缀数组 先开始nc了,觉得自动机做法是指数级的,就写了个后缀数组 具体方法是暴力,枚举起点,然后用lcp向后暴力匹配,如果失配就减少一次,我们一共有3次机会,这样每次匹配复杂度是O(1)的,所以总复 ...

  4. 关于layer.open() 弹框的使用

    在用 layer.open() 追加渲染HTML的时候,完全看不到效果,皆因layui框架需要在最后用 form.render() 方法来渲染表单才可以看到效果,写法如下: <script> ...

  5. 【转】Cache Buffer Chain 第三篇

    文章转自:http://oracle.chinaitlab.com/induction/862509.html,文章前部分转载,后部分自己加上的. Oracle数据库只读模式的CACHE BUFFER ...

  6. Flask_restful 插件实战笔记——基本概念与使用

       最近在Resetful接口设计上想法还是挺多的,也实现了一些需求!想着整理下Flask_restful插件的基本知识,方便日后的复习!   官方地址:https://flask-restful. ...

  7. unity调android ios 浏览器 uniwebview2.1使用

    uniwebview2.1使用 插件下载地址: http://download.csdn.net/detail/onafioo/9576200 示例 public class BrowserMgr { ...

  8. U3D手游《苍穹变》性能优化经验谈

    4月11日,由unity公司举办的Unite 2016大会在上海正式举行,在4月12日的案例分享专场会议上,天神互动U3D高级开发工程师康凯以手游<苍穹变>为例讲述了3DMMOARPG游戏 ...

  9. Unity(1) 编辑器结构

    5个主要视图视图,未完,持续补充... 1 Project(项目) 用于显示资源 Favorites:按资源分类显示 Assets:按目录结构显示 特殊说明 Prefabs(预设),用于场景中游戏对象 ...

  10. uoj#283. 直径拆除鸡(构造)

    传送门 好神的构造题 vfk巨巨的题解 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) fo ...