網站首頁 編程語言 正文
引言
在開發中經常會用到倒計時的按鈕,常用在發送短信驗證碼中。最差的寫法是把代碼寫在ViewController
中。這樣的話如果項目中存在多個倒計時按鈕,代碼就十分臃腫了。所以封裝一個倒計時按鈕就迫在眉睫了。傳送門HLCountDownButton,歡迎幫忙點點小星星????
- ? 支持過
xib
、storyboard
自定義樣式 - ? 支持切換前后臺計時準確
- ? 多種樣式切換
- ? 支持
CocoaPods
導入pod "HLCountDownButton"
- ? 支持全局設置樣式
演示圖
可選自定義屬性
/// 樣式,默認HLCountDownButtonTypeNormal @property (nonatomic, assign) IBInspectable NSInteger hlType UI_APPEARANCE_SELECTOR; /// 是否可用,默認YES @property (nonatomic, assign) IBInspectable BOOL hlEnabled UI_APPEARANCE_SELECTOR; /// 正常標題,默認“獲取驗證碼” @property (nonatomic, copy) IBInspectable NSString *normalTitle UI_APPEARANCE_SELECTOR; /// 重新獲取標題,默認“獲取驗證碼” @property (nonatomic, copy) IBInspectable NSString *againTitle UI_APPEARANCE_SELECTOR; /// 發送中標題格式,默認“%ds 后獲取” @property (nonatomic, copy) IBInspectable NSString *sendingTitleFormat UI_APPEARANCE_SELECTOR; /// 高亮顏色,默認0x4181FE @property (nonatomic, strong) IBInspectable UIColor *highlightedColor UI_APPEARANCE_SELECTOR; /// 非高亮顏色,默認0xd2d2d2 @property (nonatomic, strong) IBInspectable UIColor *disabledColor UI_APPEARANCE_SELECTOR; /// 圓角半徑,默認4 @property (nonatomic, assign) IBInspectable CGFloat cornerRadius UI_APPEARANCE_SELECTOR; /// 邊框寬度,默認0.5 @property (nonatomic, assign) IBInspectable CGFloat borderWidth UI_APPEARANCE_SELECTOR; /// 倒計時長,默認60s @property (nonatomic, assign) IBInspectable NSInteger countDownSize UI_APPEARANCE_SELECTOR;
3種樣式選擇
typedef NS_ENUM(NSInteger, HLCountDownButtonType) { HLCountDownButtonTypeNormal, ///< 無背景,無邊框 HLCountDownButtonTypeOnlyLine, ///< 無背景,有邊框 HLCountDownButtonTypeOnlyBackground, ///< 有背景,無邊框 };
回調說明
__weak typeof(self) weakSelf = self; self.countDownButton.startBlock = ^(){ // TODO 點擊了倒計時按鈕,這里可進行發送驗證碼操作 // [weakSelf sendCodeMsg]; };
注意:點擊了會有startBlock
回調,就不要為HLCountDownButton
添加點擊Action
了
全局樣式設置
如果您項目中多個地方使用到該組件,您可以全局設置樣式,例在AppDelegate
添加
[HLCountDownButton appearance].highlightedColor = [UIColor redColor];
注意:代碼
> appearance
> interface builder
,所以appearance設置的會覆蓋在xib或storyboard中設置的屬性,當然代碼
會覆蓋appearance
設置
原文鏈接:https://juejin.cn/post/7115308542797545508
相關推薦
- 2022-11-22 Python實例方法與類方法和靜態方法介紹與區別分析_python
- 2022-11-25 Python?RawString與open文件的newline換行符遇坑解決_python
- 2022-03-22 C#中數據類型的轉換介紹_C#教程
- 2022-04-30 C語言實現小型工資管理系統_C 語言
- 2022-05-29 消息隊列應用場景介紹_其它綜合
- 2022-10-27 Python?標準庫?fileinput與文件迭代器_python
- 2022-08-26 C++超集C++/CLI模塊的基本語法_C 語言
- 2022-08-31 在.Net?Framework應用中請求HTTP2站點的問題解析_實用技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支