UILabel分类扩展属性字符串的使用
来源:互联网 发布:如何在一个数据区间 编辑:程序博客网 时间:2024/05/17 09:10
#import <UIKit/UIKit.h>@interface UILabel (AttributedString)- (void)setTextFont:(UIFont *)font atRange:(NSRange)range;- (void)setTextColor:(UIColor *)color atRange:(NSRange)range;- (void)setTextLineSpace:(float)space atRange:(NSRange)range;- (void)setTextFont:(UIFont *)font color:(UIColor *)color atRange:(NSRange)range;- (void)setTextAttributes:(NSDictionary *)attributes atRange:(NSRange)range;@end
#import "UILabel+AttributedString.h"@implementation UILabel (AttributedString)- (void)setTextFont:(UIFont *)font atRange:(NSRange)range{ [self setTextAttributes:@{NSFontAttributeName : font} atRange:range];}- (void)setTextColor:(UIColor *)color atRange:(NSRange)range{ [self setTextAttributes:@{NSForegroundColorAttributeName : color} atRange:range];}- (void)setTextLineSpace:(float)space atRange:(NSRange)range{ NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.text]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:space];//调整行间距 [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.text length])]; self.attributedText = attributedString; [self sizeToFit];}- (void)setTextFont:(UIFont *)font color:(UIColor *)color atRange:(NSRange)range{ [self setTextAttributes:@{NSFontAttributeName : font, NSForegroundColorAttributeName : color} atRange:range];}- (void)setTextAttributes:(NSDictionary *)attributes atRange:(NSRange)range{ NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText]; for (NSString *name in attributes) { [mutableAttributedString addAttribute:name value:[attributes objectForKey:name] range:range]; } // [mutableAttributedString setAttributes:attributes range:range]; error self.attributedText = mutableAttributedString;}@end
0 0
- UILabel分类扩展属性字符串的使用
- 属性化字符串在uilabel上的使用
- UILabel特殊属性的使用
- UIlabel特殊属性的使用
- UILabel 的基本使用和扩展
- UILabel的一些常用属性、NSAttributedString属性字符串
- UILabel属性使用
- UILabel的属性
- UILabel的各种属性
- UILabel 的属性
- UILabel的属性总结
- UILabel的常用属性
- UILabel的各种属性
- 分类的使用 对NSString的扩展
- UILabel的各种属性与方法的使用
- UILabel的各种属性与方法的使用
- ios-王云鹤 UIlabel的各种属性与方法的使用
- UILabel的各种属性与方法的使用(转)
- Timus 1893 A380
- C++程序设计语言练习11.3
- CCF推荐国际刊物会议列表2015
- spring_boot 发布成war包 ,部署到外部的tomcat
- laravel编辑内容提交入库时传到update()方法
- UILabel分类扩展属性字符串的使用
- iOS5,iOS6,iOS7中UITabBarController,UINavigationController等界面中的旋转问题总结
- zookeeper选主和同步机制
- MySQL高可用之:MySQL-MMM
- 使用Socket处理跨进程的实时聊天
- 短信群发
- 【Struts2】:基于OGNL的类型转换
- 编程的智慧
- 和matlab一样的轻量级