加功能
295060456 opened this issue · comments
1、富文本
2、渐变色lab
1、富文本这块建议把相关的值用model进行管理进行传输,我有代码https://github.com/295060456/JobsIM见
#import "NSObject+RichText.h",
我没有pod
这么使用
{// 情况 1
NSMutableArray *tempDataMutArr = NSMutableArray.array;
RichLabelDataStringsModel *title_1_Model = RichLabelDataStringsModel.new;
RichLabelDataStringsModel *title_2_Model = RichLabelDataStringsModel.new;
{
title_1_Model.dataString = @"邀请好友,";
RichLabelFontModel *richLabelFontModel = RichLabelFontModel.new;
richLabelFontModel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
richLabelFontModel.range = NSMakeRange(0, title_1_Model.dataString.length);
RichLabelTextCorModel *richLabelTextCorModel = RichLabelTextCorModel.new;
richLabelTextCorModel.cor = RGBCOLOR(46, 51, 77);
richLabelTextCorModel.range = NSMakeRange(0, title_1_Model.dataString.length);
title_1_Model.richLabelFontModel = richLabelFontModel;
title_1_Model.richLabelTextCorModel = richLabelTextCorModel;
}
{
title_2_Model.dataString = @"无限赚抖币";
RichLabelFontModel *richLabelFontModel = RichLabelFontModel.new;
richLabelFontModel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
richLabelFontModel.range = NSMakeRange(title_1_Model.dataString.length, title_2_Model.dataString.length);
RichLabelTextCorModel *richLabelTextCorModel = RichLabelTextCorModel.new;
richLabelTextCorModel.cor = RGBCOLOR(231, 74, 99);
richLabelTextCorModel.range = NSMakeRange(title_1_Model.dataString.length, title_2_Model.dataString.length);
title_2_Model.richLabelFontModel = richLabelFontModel;
title_2_Model.richLabelTextCorModel = richLabelTextCorModel;
}
[tempDataMutArr addObject:title_1_Model];
[tempDataMutArr addObject:title_2_Model];
_titleLab.attributedText = [NSObject makeRichTextWithDataConfigMutArr:tempDataMutArr];
}
2、渐变色这块看下
以下是代码:
UILabel *label = [_tableView.ly_emptyView valueForKey:@"titleLabel"];
UIGraphicsBeginImageContextWithOptions(label.bounds.size, NO, [UIScreen mainScreen].scale);
CGContextRef context = UIGraphicsGetCurrentContext();
//绘制渐变层
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradientRef = CGGradientCreateWithColors(colorSpaceRef,
(__bridge CFArrayRef)@[(id)[UIColor redColor].CGColor,(id)[UIColor greenColor].CGColor],
NULL);
CGPoint startPoint = CGPointZero;
CGPoint endPoint = CGPointMake(CGRectGetMaxX(label.bounds), CGRectGetMaxY(label.bounds));
CGContextDrawLinearGradient(context, gradientRef, startPoint, endPoint, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
//取到渐变图片
UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext();
//释放资源
CGColorSpaceRelease(colorSpaceRef);
CGGradientRelease(gradientRef);
UIGraphicsEndImageContext();
label.textColor = [UIColor colorWithPatternImage:gradientImage];
都是干货哈。
#import "UIColor+Gradient.h"
@implementation UIColor (Gradient)
+(UIColor *)gradientCorDataMutArr:(NSMutableArray <UIColor >_Nullable)CorDataMutArr
startPoint:(CGPoint)startPoint
endPoint:(CGPoint)endPoint
opaque:(BOOL)opaque
withTargetLabel:(UILabel *_Nonnull)targetLabel{
if (!CorDataMutArr) {
CorDataMutArr = NSMutableArray.array;
[CorDataMutArr addObject:(id)[UIColor redColor].CGColor];
[CorDataMutArr addObject:(id)[UIColor greenColor].CGColor];
}else{
for (int t = 0; t < CorDataMutArr.count; t++) {
[CorDataMutArr replaceObjectAtIndex:t
withObject:(id)CorDataMutArr[t].CGColor];
}
}
UIGraphicsBeginImageContextWithOptions(targetLabel.bounds.size,
opaque,
[UIScreen mainScreen].scale);
CGContextRef context = UIGraphicsGetCurrentContext();
//绘制渐变层
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradientRef = CGGradientCreateWithColors(colorSpaceRef,
(__bridge CFArrayRef)CorDataMutArr,
NULL);
CGPoint EndPoint = endPoint;
if (CGPointEqualToPoint(endPoint, CGPointZero)) {
EndPoint = CGPointMake(CGRectGetMaxX(targetLabel.bounds),
CGRectGetMaxY(targetLabel.bounds));
}
CGContextDrawLinearGradient(context,
gradientRef,
startPoint,
EndPoint,
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
//取到渐变图片
UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext();
//释放资源
CGColorSpaceRelease(colorSpaceRef);
CGGradientRelease(gradientRef);
UIGraphicsEndImageContext();
return [UIColor colorWithPatternImage:gradientImage];
}
这里我更正下,以下是最新解决方案:
.h
#if __has_include(<LYEmptyView/LYEmptyViewHeader.h>)
#import <LYEmptyView/LYEmptyViewHeader.h>
#else
#import "LYEmptyViewHeader.h"
#endif
NS_ASSUME_NONNULL_BEGIN
@interface EmptyView : LYEmptyView
-
(instancetype)diyEmptyViewWithTitle:(NSString *_Nullable)title;
-
(instancetype)diyEmptyActionViewWithTarget:(id)target
action:(SEL)action;
NS_ASSUME_NONNULL_END
/*
_tableView.ly_emptyView = [EmptyView diyEmptyViewWithTitle:@"您还未关注账号"];
*/
.m
#import "EmptyView.h"
@implementation EmptyView
-
(instancetype)diyEmptyViewWithTitle:(NSString *_Nullable)title{
if ([NSString isNullString:title]) {
title = @"快来将我填满吧";
}
return [EmptyView emptyViewWithImageStr:@"暂无数据"
titleStr:title
detailStr:@""];
} -
(instancetype)diyEmptyActionViewWithTarget:(id)target
action:(SEL)action{
return [EmptyView emptyActionViewWithImageStr:@"noNetwork"
titleStr:@"无网络连接"
detailStr:@"请检查你的网络连接是否正确!"
btnTitleStr:@"重新加载"
target:target
action:action];
}
-(void)drawRect:(CGRect)rect{
[super drawRect:rect];
self.autoShowEmptyView = NO; //如果想要DemoEmptyView的效果都不是自动显隐的,这里统一设置为NO,初始化时就不必再一一去写了
self.titleLabFont = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
UILabel *label = [self valueForKey:@"titleLabel"];
UIColor *cor = [UIColor gradientCorDataMutArr:[NSMutableArray arrayWithArray:@[RGBCOLOR(247, 131, 97),RGBCOLOR(245, 75, 100)]]
startPoint:CGPointZero
endPoint:CGPointZero
opaque:NO
withTargetLabel:label];
self.titleLabTextColor = cor;
}
- (void)prepare{
[super prepare];
}
因为:
// 上下文为 nil 或者 targetLabel没有被约束撑开都会失败
+(UIColor *)gradientCorDataMutArr:(NSMutableArray <UIColor >_Nullable)CorDataMutArr
startPoint:(CGPoint)startPoint
endPoint:(CGPoint)endPoint
opaque:(BOOL)opaque
withTargetLabel:(UILabel *_Nonnull)targetLabel;