今天分享一個我封裝的UIView的傳送帶邊框,帶動畫的,也可以關(guān)閉動畫,可以設(shè)置圓角,可以設(shè)置顏色漸變,用法非常簡單,先看看效果圖
效果圖
UIViewDashedBorder git地址 用法非常簡便,有用的話給個star唄
UIViewDashedBorder git地址 用法非常簡便,有用的話給個star唄
UIViewDashedBorder git地址 用法非常簡便,有用的話給個star唄
代碼用法如下: 效果圖中的四種效果,對應(yīng)代碼四種寫法
// 1.
UIView *dashedView1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 100)];
[self.view addSubview:dashedView1];
[dashedView1 startDashedLayerRunning];
//dashedView1.backgroundColor = [UIColor greenColor];
// 2.
UIView *dashedView2 = [[UIView alloc] initWithFrame:CGRectMake(50, 170, 200, 100)];
[self.view addSubview:dashedView2];
DashedConfig *config = [DashedConfig defaultConfig];
config.openAnimation = NO;
[dashedView2 startDashedLayerRunningWithContig:config];
//dashedView2.backgroundColor = [UIColor greenColor];
// 3.
UIView *dashedView3 = [[UIView alloc] initWithFrame:CGRectMake(50, 290, 200, 100)];
[self.view addSubview:dashedView3];
DashedConfig *config1 = [DashedConfig defaultConfig];
config1.openAnimation = YES;
config1.colors = @[(id)[UIColor redColor].CGColor];
config1.solidPointCount = 6;
config1.dashedPointCount = 6;
config1.lineWidth = 2;
config1.eachPoint = 2;
config1.duration = 0.1;
config1.circleDuration = 15;
[dashedView3 startDashedLayerRunningWithContig:config1];
// 4.
UIView *dashedView4 = [[UIView alloc] initWithFrame:CGRectMake(50, 410, 200, 100)];
[self.view addSubview:dashedView4];
DashedConfig *config4 = [DashedConfig defaultConfig];
config4.cornerRidus = 10;
[dashedView4 startDashedLayerRunningWithContig:config4];
文件目錄以及.h

在這里插入圖片描述
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface DashedConfig : NSObject
/// 實線和虛線的長度, 循環(huán)他倆之和, 控件寬度最少要大于兩個之和
@property (nonatomic, assign) NSInteger solidPointCount;
@property (nonatomic, assign) NSInteger dashedPointCount;
@property (nonatomic, assign, getter=isOpenAnimation) BOOL openAnimation;
@property (nonatomic, copy) NSArray *colors;
@property (nonatomic, assign) CGFloat lineWidth;
/// 一步幾個單位 pt
@property (nonatomic, assign) NSInteger eachPoint;
/// 多久移動一步
@property (nonatomic, assign) double duration;
/// 顏色多久循環(huán)一周
@property (nonatomic, assign) double circleDuration;
/// 半徑, 0時為直角
@property (nonatomic, assign) CGFloat cornerRidus;
+ (instancetype)defaultConfig;
@end
#import <UIKit/UIKit.h>
#import "DashedConfig.h"
@class AngleGradientLayer;
@interface UIView (DashedBorder)
// 前綴避免與其他庫重名
@property (nonatomic, strong, readonly) AngleGradientLayer *pss_angleLayer;
@property (nonatomic, strong, readonly) CAShapeLayer *pss_shapeLayer;
@property (nonatomic, strong, readonly) NSTimer *pss_timer;
@property (nonatomic, assign, readonly) NSInteger pss_Count;
@property (nonatomic, strong, readonly) DashedConfig *pss_config;
@property (nonatomic, strong, readonly) CALayer *pss_layer;
/// 如果存在layer, 直接retun, 并不會刷新新的config - (推薦使用)
- (void)startDashedLayerRunning;
/// 如果存在layer, 直接retun, 并不會刷新新的config - (推薦使用)
- (void)startDashedLayerRunningWithContig:(DashedConfig *)config;
/// 會remove邊框相關(guān)的layer 重新創(chuàng)建, 會刷新新的config - (刷新時才用)
- (void)refreshByConfig:(DashedConfig *)config;
@end
碼字碼代碼不易,喜歡的話別忘了Star哦