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 ...
随机推荐
- dubbo项目中包的依赖说明
依赖 (+) (#) 必需依赖 JDK1.5+ 理论上Dubbo可以只依赖JDK,不依赖于任何三方库运行,只需配置使用JDK相关实现策略. 缺省依赖 通过mvn dependency:tree > ...
- Count Subsets
题意: 给一集合 $S = \{ 1,2, ... , n \} $,取两个S的子集 A和B,使得A不是B的子集,且B不是A的子集. 解法: 1.牛顿展开 我们采用容斥,显然有 $$ans(n) = ...
- opencv MatExpr MatOp
opencv提供了很多Mat的操作,其中涉及到两个重要的类:MatOp和MatExpr C++: MatExpr abs(const Mat& m) C++: void absdiff(Inp ...
- 安装mosquitto报缺少dll文件的错误
解决:下载缺少的dll组件,放到安装目录. 报错:The procedure entry point CRYPTO_memcmp could not be located in the dynami ...
- 简易DIV垂直居中阴影层笼罩JS实现
$(document).ready(init); function init() { var h = $(window).height(); var w = $(window).width(); /* ...
- 201621123016 《Java程序设计》第九周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至 ...
- iOS滑动tableView来改变导航栏的颜色
- (void)viewDidLoad { [super viewDidLoad];[self initTableView];}- (NSInteger)numberOfSectionsInTable ...
- lightoj 1096【矩阵快速幂(作为以后的模板)】
基础矩阵快速幂何必看题解 #include <bits/stdc++.h> using namespace std; /* 0 1 2 3 4 5 6 7 0 0 0 */ const i ...
- HDU4791【杂】
题意: 给你一个从0开始的区间si,每个区间是前闭后开,[ s[i] , s[i+1] ), 然后再给你个一个pi,代表你在区间[ s[i] , s[i+1] )里面买东西的单价是pi,给出的s1一定 ...
- AtCoder Regular Contest 061 E - すぬけ君の地下鉄旅行【最短路】
具体题解又要搬大哥的了,嘿嘿~ 请点击:G点我 这道题目的难点就是同一家公司的路直接走不需要再花费,然后多了一个公司这个东西,这个不像是边的副权值(瞎说的)之类的东西,这是对于路来说的,路的属性... ...