features:1.新绚多设备适配
2.修复品牌展示页&摄像头页面适配bug
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// NSString+Add.m
|
||||
// LettuceFinancial
|
||||
//
|
||||
// Created by roadroor on 2017/12/8.
|
||||
// Copyright © 2017年 Roadoor. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSString+Add.h"
|
||||
|
||||
@implementation NSString (Add)
|
||||
+ (NSMutableAttributedString *)ls_changeFontAndColor:(UIFont *)font Color:(UIColor *)color TotalString:(NSString *)totalString lineSpace:(CGFloat)spacing textAlignment:(NSTextAlignment)alignment SubStringArray:(NSArray *)subArray{
|
||||
NSMutableAttributedString *attributedStr = [self ls_changeFontAndColor:font Color:color TotalString:totalString SubStringArray:subArray];
|
||||
|
||||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
[paragraphStyle setLineSpacing:spacing];
|
||||
[paragraphStyle setAlignment:alignment];
|
||||
[attributedStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalString length])];
|
||||
return attributedStr;
|
||||
}
|
||||
|
||||
|
||||
+ (NSMutableAttributedString *)ls_changeFontAndColor:(UIFont *)font Color:(UIColor *)color TotalString:(NSString *)totalString lineSpace:(CGFloat)spacing SubStringArray:(NSArray *)subArray {
|
||||
NSMutableAttributedString *attributedStr = [self ls_changeFontAndColor:font Color:color TotalString:totalString SubStringArray:subArray];
|
||||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
[paragraphStyle setLineSpacing:spacing];
|
||||
[attributedStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalString length])];
|
||||
return attributedStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 改变某些文字的颜色 并单独设置其字体
|
||||
*
|
||||
* @param font 设置的字体
|
||||
* @param color 颜色
|
||||
* @param totalString 总的字符串
|
||||
* @param subArray 想要变色的字符数组
|
||||
*
|
||||
* @return 生成的富文本
|
||||
*/
|
||||
|
||||
+ (NSMutableAttributedString *)ls_changeFontAndColor:(UIFont *)font Color:(UIColor *)color TotalString:(NSString *)totalString SubStringArray:(NSArray *)subArray {
|
||||
if (!totalString.length) {return [NSMutableAttributedString new];}
|
||||
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:totalString];
|
||||
if (!subArray.count) {return attributedStr;}
|
||||
for (NSString *rangeStr in subArray) {
|
||||
NSRange range = [totalString rangeOfString:rangeStr options:NSBackwardsSearch];
|
||||
if (color) {
|
||||
[attributedStr addAttribute:NSForegroundColorAttributeName value:color range:range];
|
||||
}
|
||||
if (font) {
|
||||
[attributedStr addAttribute:NSFontAttributeName value:font range:range];
|
||||
}
|
||||
}
|
||||
|
||||
return attributedStr;
|
||||
}
|
||||
|
||||
+ (NSMutableAttributedString *)ls_changeFontAndColor:(UIFont *)font Color:(UIColor *)color TotalString:(NSString *)totalString SubRangeArray:(NSArray<NSValue*> *)subArray{
|
||||
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:totalString];
|
||||
for (NSNumber *obj in subArray) {
|
||||
if (color) {
|
||||
[attributedStr addAttribute:NSForegroundColorAttributeName value:color range:obj.rangeValue];
|
||||
}
|
||||
if (font) {
|
||||
[attributedStr addAttribute:NSFontAttributeName value:font range:obj.rangeValue];
|
||||
}
|
||||
}
|
||||
return attributedStr;
|
||||
}
|
||||
|
||||
+(NSMutableAttributedString *)ls_changeLastLettersLFontAndColor:(UIFont *)font Color:(UIColor *)color TotalString:(NSString *)totalString{
|
||||
if (!totalString.length) {return [NSMutableAttributedString new];}
|
||||
NSArray *range = [NSArray arrayWithObject:[NSValue valueWithRange:NSMakeRange(totalString.length-1, 1)]];
|
||||
return [self ls_changeFontAndColor:font Color:color TotalString:totalString SubRangeArray:range];
|
||||
}
|
||||
|
||||
+ (NSMutableAttributedString *)ls_changePrefixString:(NSString *)prefixString PrefixFont:(UIFont *)prefixFont PrefixColor:(UIColor *)prefixColor SuffixesString:(NSString*)suffixesString SuffixesFont:(UIFont *)suffixesFont SuffixesColor:(UIColor *)suffixesColor{
|
||||
if (!prefixString.length) {return [NSMutableAttributedString new];}
|
||||
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:prefixString attributes:@{NSForegroundColorAttributeName: prefixColor,NSFontAttributeName : prefixFont}];
|
||||
if (suffixesString.length) {
|
||||
NSMutableAttributedString *attributedStr2 = [[NSMutableAttributedString alloc] initWithString:suffixesString attributes:@{NSForegroundColorAttributeName: suffixesColor,NSFontAttributeName : suffixesFont}];
|
||||
[attributedStr appendAttributedString:attributedStr2];
|
||||
}
|
||||
return attributedStr;
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user