UIView傳送帶邊框-UIViewDashedBorder

今天分享一個我封裝的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哦

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,167評論 25 708
  • 用兩張圖告訴你,為什么你的 App 會卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 14,041評論 2 59
  • 2017年最后一天,大家堅守好崗位,一起慶祝元旦到來,餐后大家接著整理,把剩余的物品送到亞運村!感恩大家! 女朋友...
    陽光創(chuàng)客敖偉偉閱讀 169評論 0 0
  • 帶著一股說不出的滋味離開了潼關(guān)古城,那花花綠綠的古城風(fēng)貌不由引起了陣陣嘆息,中原文明已經(jīng)墮落到低俗到如此地步...
    戎曉舒閱讀 1,153評論 0 0
  • 覺察日記 事件:本來買了兩件衣服,快遞送來一件。 感受:憤怒 想法:快遞公司太不像話,居然把包裹弄錯了。 期待:對...
    張慧哲閱讀 148評論 0 0

友情鏈接更多精彩內(nèi)容