NSMutableAttributedString 文本样式 (一)
来源:互联网 发布:五金模具设计软件 编辑:程序博客网 时间:2024/05/22 14:45
UILabel、UIBUtton等的 text的样式
UILabel *lab = [[UILabelalloc] initWithFrame:CGRectMake(10,100, 300, 100)];
lab.numberOfLines =4;
[self.viewaddSubview:lab];
//删除、替换、插入
NSMutableAttributedString *attStr = [[NSMutableAttributedStringalloc] initWithString:@"你好吗,我很好。你好吗,我很好。你好吗,我很好。你好吗,我很好。你好吗,我很好。你好吗,我很好。你好吗,我很好。我很好。"];
// 添加删除线
[attStr addAttribute:NSStrikethroughStyleAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle]range:NSMakeRange(0,3)];
// 添加下划线
[attStr addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle]range:NSMakeRange(4,3)];
// 某个字体大小
[attStr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:22]range:NSMakeRange(8,3)];
// 字体颜色
[attStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:NSMakeRange(12,3)];
// 设置笔画的粗细
[attStr addAttribute:NSStrokeWidthAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleDouble]range:NSMakeRange(16,3)];
// label 的背景颜色
[attStr addAttribute:NSBackgroundColorAttributeNamevalue:[UIColorgreenColor] range:NSMakeRange(20,3)];
// label上文本颜色(也会影响删除线和下划线的颜色)
[attStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorblueColor] range:NSMakeRange(24,3)];
[attStr addAttribute:NSStrikethroughStyleAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle]range:NSMakeRange(24,3)];
[attStr addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle]range:NSMakeRange(24,3)];
//文本内容颜色和删除线、下划线颜色不一样
// NSStrokeColorAttributeName 单独设置没有效果
// 必须与NSStrokeWidthAttributeName一起设置
[attStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorblueColor] range:NSMakeRange(28,3)];
[attStr addAttribute:NSStrikethroughStyleAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle]range:NSMakeRange(28,3)];
[attStr addAttribute:NSStrokeColorAttributeNamevalue:[UIColorredColor] range:NSMakeRange(28,3)]; //cyanColor
[attStr addAttribute:NSStrokeWidthAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle]range:NSMakeRange(28,3)];
// 笔画的阴影效果
NSShadow *shadow = [[NSShadowalloc] init];
[shadow setShadowColor:[UIColorredColor]];
[shadow setShadowBlurRadius:4];
[shadow setShadowOffset:CGSizeMake(2,2)];
[attStr addAttribute:NSShadowAttributeNamevalue:shadow range:NSMakeRange(32,3)];
//
[attStr addAttribute:NSParagraphStyleAttributeNamevalue:[NSNumbernumberWithInt:NSUnderlineStyleSingle]range:NSMakeRange(36,3)];
//
//[attStr addAttribute:NSVerticalGlyphFormAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(28, 4)];
lab.attributedText = attStr;
- NSMutableAttributedString 文本样式 (一)
- IOS学习(一) 使用NSMutableAttributedString样式文本
- NSMutableAttributedString文本样式设置以及富文本展示
- 12-富文本 NSMutableAttributedString
- 富文本 ---- NSMutableAttributedString
- NSMutableAttributedString实现富文本
- ios富文本NSMutableAttributedString
- NSMutableAttributedString富文本
- NSMutableAttributedString富文本处理
- 富文本处理NSMutableAttributedString
- UILabel点击调用电话以及邮箱,UILabel超链接效果 NSMutableAttributedString文本样式设置
- Android文本样式(一)
- NSMutableAttributedString IOS中的富文本
- 富文本NSAttributedString与NSMutableAttributedString
- NSMutableAttributedString/NSAttributedString 富文本设置
- NSMutableAttributedString富文本的实现
- 富文本的使用 NSMutableAttributedString
- iOS NSMutableAttributedString 实现富文本
- cocos2d-x 截屏图片
- HDU 2025 查找最大元素
- 三松松散散
- android 解压缩功能.
- HDU 2042 不容易系列之二
- NSMutableAttributedString 文本样式 (一)
- 【算法学习笔记】16.暴力求解法04 回溯法03 剪枝法 带宽
- Android中SAX解析XML
- 健康睡眠要保持的六条规则
- iosUILabel的用法
- poj 3630(phone list)
- 【热门收藏】iOS开发人员必看的精品资料(100个)——下载目录
- 多边形区域填充算法--扫描线种子填充算法
- Lua的OS库