AttributedString设置字体属性
来源:互联网 发布:网络优化工程师 西安 编辑:程序博客网 时间:2024/05/21 17:37
///改变字体大小及字体颜色,区分字体的颜色还是字体背景色
+ (void)AttributedString:(NSMutableAttributedString *)attributedStr
text:(NSString *)text font:(UIFont *)font color:(UIColor *)color bgColor:(BOOL)bgColor
{
if ((!attributedStr || 0 == attributedStr.length) || (!text || 0 == text.length) || !font || !color)
{
return;
}
//字体设置范围
NSRange range = [attributedStr.string rangeOfString:text];
//字体大小
[attributedStr addAttribute:NSFontAttributeName
value:font
range:range];
//字体颜色
[attributedStr addAttribute:(bgColor ? NSBackgroundColorAttributeName : NSForegroundColorAttributeName)
value:color
range:range];
}
///设置字体的下划线,或删除线,及其线条大小、颜色与类型(如下划线单线类型NSUnderlineStyleSingle)
+ (void)AttributedString:(NSMutableAttributedString *)attributedStr
text:(NSString *)text textColor:(UIColor *)textcolor
lineStyle:(BOOL)delete lineType:(NSInteger)type lineWidth:(CGFloat)width lineColor:(UIColor *)color
{
if ((!attributedStr || 0 == attributedStr.length) || (!text || 0 == text.length))
{
return;
}
//字体设置范围
NSRange range = [attributedStr.string rangeOfString:text];
//设置字体颜色
[attributedStr addAttribute:NSStrokeColorAttributeName
value:textcolor
range:range];
//线条大小
[attributedStr addAttribute:NSStrokeWidthAttributeName
value:[NSNumber numberWithFloat:width]
range:range];
//线条颜色
[attributedStr addAttribute:NSForegroundColorAttributeName
value:color
range:range];
// 线条样式,删除线,或下划线
[attributedStr addAttribute:(delete ? NSStrikethroughStyleAttributeName : NSUnderlineStyleAttributeName)
value:[NSNumber numberWithInteger:type]
range:range];
}
///设置字体阴影色
+ (void)AttributedString:(NSMutableAttributedString *)attributedStr
text:(NSString *)text shadowColor:(UIColor *)color
{
if ((!attributedStr || 0 == attributedStr.length) || (!text || 0 == text.length))
{
return;
}
//字体设置范围
NSRange range = [attributedStr.string rangeOfString:text];
//字体阴影色
// [attributedStr addAttribute:NSShadowAttributeName
// value:color
// range:range];
//笔画的阴影效果
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = color; //阴影颜色
shadow.shadowBlurRadius = 3.0; //阴影扩散范围
shadow.shadowOffset = CGSizeMake(0.0, 0.0); //阴影偏移位置
[attributedStr addAttribute:NSShadowAttributeName
value:shadow
range:range];
}
- AttributedString设置字体属性
- UILabel的AttributedString设置
- AttributedString属性字符串的使用方法
- AttributedString
- AttributedString
- AttributedString
- 设置字体属性
- 设置属性字体
- pain设置字体属性
- 设置控件的字体属性
- C#设置textBox字体属性
- IOS-UI设置字体属性
- Android 设置字体加粗属性
- css字体设置相关属性
- UILabel属性, AttributedString字符串属性 (从网络搜集整理)
- ios-给AttributedString添加属性以及如何去取
- HTML标记【字体的属性设置】!
- Android中Paint字体属性的设置
- java 0基础学习总结
- Android中Serializable和Parcelable的用法及区别
- 求解逆波兰表达式的值,回文数字的判断&&栈的应用
- 【VB.NET机房重构】DataGridView导出Excel
- iOS完整学习路线图
- AttributedString设置字体属性
- 解决android中出现的无法加载library的问题
- bootstrap的导航路径和分页器
- 关于softmax 函数求导
- 黑马程序员---高级-反射
- 深刻教训,C#中MVC控制器名称,非区域中不能为UploadController
- 关于swing的一些收获
- javase学习之路—set,get方法
- Spring3+hibernate4利用Annotation实现事务