属性字符串NSAttributedString简易教程
来源:互联网 发布:windows linux 编辑:程序博客网 时间:2024/05/30 23:02
</pre><p><span style="font-size:18px"><strong>简单步骤</strong></span></p><p></p><pre name="code" class="objc"><span style="font-size:14px;"><pre name="code" class="objc">NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc]initWithString:normalString]; [attriString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:titleSize] range:NSMakeRange(0 , a)]; [attriString addAttribute:NSForegroundColorAttributeName value:textColor range:NSMakeRange(a, normalString.length - a)]; [attriLabel setAttributedTitle:attriString forState:UIControlStateNormal]; </span>
属性一览
/************************ Attributes ************************/// Predefined character attributes for text. If the key is not in the dictionary, then use the default values as described below.UIKIT_EXTERN NSString * const NSFontAttributeName NS_AVAILABLE(10_0, 6_0); // UIFont, default Helvetica(Neue) 12UIKIT_EXTERN NSString * const NSParagraphStyleAttributeName NS_AVAILABLE(10_0, 6_0); // NSParagraphStyle, default defaultParagraphStyleUIKIT_EXTERN NSString * const NSForegroundColorAttributeName NS_AVAILABLE(10_0, 6_0); // UIColor, default blackColorUIKIT_EXTERN NSString * const NSBackgroundColorAttributeName NS_AVAILABLE(10_0, 6_0); // UIColor, default nil: no backgroundUIKIT_EXTERN NSString * const NSLigatureAttributeName NS_AVAILABLE(10_0, 6_0); // NSNumber containing integer, default 1: default ligatures, 0: no ligaturesUIKIT_EXTERN NSString * const NSKernAttributeName NS_AVAILABLE(10_0, 6_0); // NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled.UIKIT_EXTERN NSString * const NSStrikethroughStyleAttributeName NS_AVAILABLE(10_0, 6_0); // NSNumber containing integer, default 0: no strikethroughUIKIT_EXTERN NSString * const NSUnderlineStyleAttributeName NS_AVAILABLE(10_0, 6_0); // NSNumber containing integer, default 0: no underlineUIKIT_EXTERN NSString * const NSStrokeColorAttributeName NS_AVAILABLE(10_0, 6_0); // UIColor, default nil: same as foreground colorUIKIT_EXTERN NSString * const NSStrokeWidthAttributeName NS_AVAILABLE(10_0, 6_0); // NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)UIKIT_EXTERN NSString * const NSShadowAttributeName NS_AVAILABLE(10_0, 6_0); // NSShadow, default nil: no shadowUIKIT_EXTERN NSString *const NSTextEffectAttributeName NS_AVAILABLE(10_10, 7_0); // NSString, default nil: no text effectUIKIT_EXTERN NSString * const NSAttachmentAttributeName NS_AVAILABLE(10_0, 7_0); // NSTextAttachment, default nilUIKIT_EXTERN NSString * const NSLinkAttributeName NS_AVAILABLE(10_0, 7_0); // NSURL (preferred) or NSStringUIKIT_EXTERN NSString * const NSBaselineOffsetAttributeName NS_AVAILABLE(10_0, 7_0); // NSNumber containing floating point value, in points; offset from baseline, default 0UIKIT_EXTERN NSString * const NSUnderlineColorAttributeName NS_AVAILABLE(10_0, 7_0); // UIColor, default nil: same as foreground colorUIKIT_EXTERN NSString * const NSStrikethroughColorAttributeName NS_AVAILABLE(10_0, 7_0); // UIColor, default nil: same as foreground colorUIKIT_EXTERN NSString * const NSObliquenessAttributeName NS_AVAILABLE(10_0, 7_0); // NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skewUIKIT_EXTERN NSString * const NSExpansionAttributeName NS_AVAILABLE(10_0, 7_0); // NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansionUIKIT_EXTERN NSString * const NSWritingDirectionAttributeName NS_AVAILABLE(10_6, 7_0); // NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters. The control characters can be obtained by masking NSWritingDirection and NSTextWritingDirection values. LRE: NSWritingDirectionLeftToRight|NSWritingDirectionEmbedding, RLE: NSWritingDirectionRightToLeft|NSWritingDirectionEmbedding, LRO: NSWritingDirectionLeftToRight|NSWritingDirectionOverride, RLO: NSWritingDirectionRightToLeft|NSWritingDirectionOverride,UIKIT_EXTERN NSString * const NSVerticalGlyphFormAttributeName NS_AVAILABLE(10_7, 6_0); // An NSNumber containing an integer value. 0 means horizontal text. 1 indicates vertical text. If not specified, it could follow higher-level vertical orientation settings. Currently on iOS, it's always horizontal. The behavior for any other value is undefined.
参考资料
[1]: NSAttributedString 详解[2]: iOS中属性化字符串
0 0
- 属性字符串NSAttributedString简易教程
- NSAttributedString 详解(属性字符串)
- NSAttributedString字符串属性
- iOS-属性字符串NSAttributedString
- iOS NSAttributedString(属性字符串)
- Objective-C属性字符串NSAttributedString
- 带属性的字符串 NSMutableAttributedString/NSAttributedString
- 带属性的字符串 NSMutableAttributedString/NSAttributedString
- iOS - NSAttributedString字符串属性详解
- NSAttributedString 属性
- NSAttributedString属性
- UILabel的一些常用属性、NSAttributedString属性字符串
- UIKit 带属性的字符串 NSAttributedString、NSMutableAttributedString、NSTextStorge(未完成)
- NSAttributedString的属性
- NSAttributedstring的属性
- 字符属性NSAttributedString
- NSAttributedString属性详解
- NSAttributedString属性解析
- 自定义AlertDialog,模仿Ios弹出框
- 如何创建上下文菜单
- 基本的线程机制(三)
- Android 设置Activity窗体 不显示标题和全屏显示
- TCP协议中的三次握手和四次挥手(图解)
- 属性字符串NSAttributedString简易教程
- Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
- Netty框架初探
- Linux(Ubuntu)定时提醒/执行任务
- OpenCV将彩色视频转换为灰度视频并保存
- Redis Cluster(Redis 3.X)设计要点
- ObservableCollection集合进行排序
- 更轻量的 View Controllers
- java cloassLoader大仙儿