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 ...
随机推荐
- UVaLive 6854 City (暴力)
题意:给定一个 n*m 的矩阵,表示有多少条道路与它相连,其中有一个-1,表示未知,道路只能横着和竖着,求-1处的值. 析:根据题意可知,一个点,与其他周围的四个点都可能相连的,也就是说肯定有共用道路 ...
- UVa 1641 ASCII Area (计算几何,水题)
题意:给定一个矩阵,里面有一个多边形,求多边形的面积. 析:因为是在格子里,并且这个多边形是很规则的,所以所有格子不是全属于多边形就是全不属于,或者一半,并且我们可以根据"/"和“ ...
- Eclipse+Maven+TestNg+ReportNg 生成测试报告
http://blog.csdn.net/a542551042/article/details/46729585
- E20190414-hm
ease n. 安逸; 容易; 轻松,舒适; 不拘束,自在; (for/with ease of) repetition n. 重复,反复; 背诵; 复制品,副本; [乐] 复唱,复奏,重奏; gl ...
- 51nod 1021【区间DP】
思路: dp[ i ] [ j ]代表取[ i ,j ]区间石子的最小值,然后dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]); # ...
- 混用ngui和ugui渲染顺序问题
http://blog.csdn.net/xtxy/article/details/38332801 为NGUI panel 添加 sorting layer 接着上一篇文章的问题,看到了老外做的一个 ...
- Unity3D - 动作动画忽略timeScale
http://blog.csdn.net/ynnmnm/article/details/46866347 最近在调战斗时的动画与特效,Unity3D对加/减速提供了Time.timeScale支持.但 ...
- golang开发:(二)安装 Golang
当然了我们的安装都是在vagrant里面安装,vagrant ssh.不用虚拟机了,本机安装当然也可以. Mac 安装 访问下载地址,下载 go1.12.5.darwin-amd64.pkg,双击下载 ...
- nacos启动
nacos下载 https://github.com/alibaba/nacos 1.执行数据库脚本 2.修改配置文件application.propertiesspring.datasource.p ...
- CF1138D.Camp Schedule
传送门 虽然是D,但是还是Sb题,把模式串跑一遍KMP,然后把按顺序放,每次放完之后跳到对应的前缀,继续放. 如果最后1的数量还有剩,再将最后的位数全部放1 代码: #include<cstdi ...