专栏名称: CainLuo
iOS
目录
相关文章推荐
河南新闻广播  ·  2025年研考国家线发布 ·  6 小时前  
法治网  ·  河南许昌:全市对标胖东来服务理念 ·  昨天  
河南新闻广播  ·  苏英杰严重违纪违法被双开 ·  昨天  
河南发布  ·  阳光正在赶来!河南即将开启升温模式 ·  2 天前  
河南新闻广播  ·  即日起至5月底,严查! ·  3 天前  
51好读  ›  专栏  ›  CainLuo

玩转iOS开发:自己造的轮子《CLUIKit》

CainLuo  · 掘金  ·  · 2018-03-01 03:33

正文

玩转iOS开发:自己造的轮子《CLUIKit》

CLUIKit

CocoaPods Compatible
Carthage Compatible
Platform
Language

CLUIKit简介

CLUIKit 是对系统 UIKit API 进行扩展, 以及一些自己封装的 UI , API 的用法全部都在 CLUIKitExample 里, 如果在使用库遇到的一些疑惑欢迎随时 Issues 给我.

支持 CocoaPod 管理

pod 'CLUIKit'

支助

如果您觉得挺赞的话, 可以给我打赏打赏, 谢谢啦~

支付宝

CLButton@

CLButton 是对系统 UIButton 的封装并添加了一些特性:

typedef NS_ENUM(NSInteger, CLButtonStyle) {
    
    CLButtonImageTopStyle = 0,
    CLButtonImageLeftStyle,
    CLButtonImageBottomStyle,
    CLButtonImageRightStyle
};

@property (nonatomic, assign) CLButtonStyle cl_buttomImageStyle;
@property (nonatomic, assign) CGFloat cl_imageSpacing;
@property (nonatomic, assign) CGSize cl_imageSize;

CLCollectionViewController@

CLCollectionViewController 是对系统 UIViewController + UICollectionView 的封装并添加了一些特性:

UICollectionView与MJRefresh@

- (void)cl_removeRefresh;

- (void)cl_removeHeaderRefresh;

- (void)cl_removeFooterRefresh;

- (void)cl_dropDownRefresh;

- (void)cl_dropDownBeginRefresh;

- (void)cl_dropDownEndRefresh;

- (void)cl_pullUpRefresh;

- (void)cl_pullUpBeginRefresh;

- (void)cl_pullUpEndRefresh;

UICollectionView代理与数据源@

- (void)cl_setCollectionViewDelegate:(_Nullable id <UICollectionViewDelegate>)delegate
                          dataSource:(_Nullable id <UICollectionViewDataSource>)dataSource;

注册类

- (void)cl_registerClass:(nullable Class)cellClass
              identifier:(NSString *)identifier;

CLCollectionViewDataSource@

CLCollectionViewDataSource CLCollectionViewController 的数据源, 需要配合着使用:

@property (nonatomic, weak, readonly) CLCollectionViewViewModel *cl_viewModel;

- (instancetype)initCollectionViewDataSourceWithViewModel:(CLCollectionViewViewModel *)viewModel;

CLCollectionViewDelegate@

CLCollectionViewDelegate CLCollectionViewController 的代理, 需要配合着使用:

@property (nonatomic, weak, readonly) CLCollectionViewViewModel *cl_viewModel;

- (instancetype)initCollectionViewDelegateWithViewModel:(CLCollectionViewViewModel *)viewModel;

CLCollectionViewViewModel

CLCollectionViewViewModel CLCollectionViewController ViewModel , 需要配合着使用:

@property (nonatomic, weak, readonly) CLCollectionViewController *cl_collectionViewController;

@property (nonatomic, strong) NSMutableArray *cl_dataSource;

- (instancetype)initCollectionViewBaseModelWithController:(CLCollectionViewController *)viewController;

- (void)cl_collectionViewHTTPRequest;

CLNavigationController@

CLNavigationController 是针对系统 UINavigationController 的封装并添加了一些特性:

@property (nonatomic, strong) UIImage *cl_backgroundImage;

@property (nonatomic, strong) UIColor *cl_tintColor;

@property (nonatomic, strong) UIColor *cl_foregroundColor;

@property (nonatomic, strong) UIImage *cl_shadowImage;

CLNavigationController 默认重载了 pushViewController:animated: , 会在 pushViewController 的时候自动隐藏掉 UITarBar .

CLScanQRCodeController@

CLScanQRCodeController 是基于 AVFoundation 进行封装的 QRCode 扫描库, 系统默认识别十三种编码:

@property (nonatomic, strong) UIView *cl_scanQRCodeView;

@property (nonatomic, assign) BOOL cl_autoStopCaptureSessionRunning;

@property (nonatomic, weak) id <CLScanQRCodeControllerDelegate> cl_scanQRCodeControllerDelegate;

- (void)cl_startCaptureSessionRunning;

- (void)cl_stopCaptureSessionRunning;

获取数据(Block)@

@property (nonatomic, copy) void(^cl_scanQRCodeGetMetadataObjectsBlock)(NSArray *metadataObjects);

@property (nonatomic, copy) void(^cl_scanQRCodeGetMetadataStringValue)(NSString *stringValue);

获取数据(Delegate)@

- (void)cl_scanQRCodeGetMetadataObjectsWithMetadataObjects:(NSArray *)metadataObjects;

- (void)cl_scanQRCodeGetMetadataStringValue:(NSString *)stringValue;

CLTableViewController@

CLTableViewController 是针对系统 UIViewController + UITableView 的封装并添加了一些特性:

@property (nonatomic, strong, null_resettable, readonly) UITableView *cl_tableView;

- (instancetype)initTableViewControllerWithStyle:(UITableViewStyle)style;

UITableView与MJRefresh@

- (void)cl_removeRefresh;

- (void)cl_removeHeaderRefresh;

- (void)cl_removeFooterRefresh;

- (void)cl_dropDownRefresh;

- (void)cl_dropDownBeginRefresh;

- (void)cl_dropDownEndRefresh;

- (void)cl_pullUpRefresh;

- (void)cl_pullUpBeginRefresh;

- (void)cl_pullUpEndRefresh;

UITableView代理与数据源@

- (void)cl_setTableViewDelegate:(_Nullable id <UITableViewDelegate>)delegate
                     dataSource:(_Nullable id <UITableViewDataSource>)dataSource;

CLTableViewDataSource@

CLTableViewDataSource CLTableViewController 的数据源, 需要配合着使用:

@property (nonatomic, weak, readonly) CLTableViewViewModel *cl_viewModel;

- (instancetype)initTableViewDataSourceWithViewModel:(CLTableViewViewModel *)viewModel;

CLTableViewDelegate@

CLTableViewDelegate CLTableViewController 的代理, 需要配合着使用:

@property (nonatomic, weak, readonly) CLTableViewViewModel *cl_viewModel;

- (instancetype)initTableViewDelegateWithViewModel:(CLTableViewViewModel *)viewModel;

CLTableViewViewModel@

CLTableViewViewModel CLTableViewController ViewModel , 需要配合着使用:

@property (nonatomic, strong) NSMutableArray *cl_dataSource;

@property (nonatomic, weak, readonly) CLTableViewController *cl_tableViewController;

- (instancetype)initTableViewBaseModelWithController:(CLTableViewController *)viewController;

- (void)cl_tableViewHTTPRequest;

- (void)cl_configTableViewWithDataSource;

关于 CLTableViewController 封装的原理: 玩转iOS开发:打造一个低耦合可复用的《TableViewController》 .

CLTextField@

CLTextField 是针对系统 UITextField 的封装并添加了一些特性:

typedef NS_ENUM(NSInteger, CLTextFieldType) {
    
    CLTextFieldBottomNormal = 0, // default
    CLTextFieldBottomLineType
};

@property (nonatomic, assign) CLTextFieldType cl_textFieldType;

@property (nonatomic, strong) UIColor *cl_lineColor;

CLToolBarListView@

CLToolBarListView 是在系统 UIView 上封装的一个横向菜单栏的控件(未来会重构一个更灵活的):

typedef NS_ENUM(NSInteger, CLToolBarStyle) {
    CLToolBarNormalStyle = 0,
    CLToolBarSeparationStyle
};

- (instancetype)initToolBarWithFrame:(CGRect)frame;

@property (nonatomic, assign) CLToolBarStyle cl_toolBarStyle;

@property (nonatomic, assign) BOOL cl_titleAdjustsFontSizeToFitWidth;

@property (nonatomic, strong) NSArray  *cl_titleArray;

@property (nonatomic, strong) UIColor *cl_selectedColor;

@property (nonatomic, strong) UIColor *cl_deselectColor;

@property (nonatomic, strong) UIColor *cl_barBakcgroundColor;

@property (nonatomic, strong) UIColor *cl_bottomLineColor;

@property (nonatomic, strong) UIColor *cl_selectedLineColor;

@property (nonatomic, assign) NSInteger cl_textFont;

@property (nonatomic, assign) CGFloat cl_buttonSpacing;

@property (nonatomic, assign) BOOL cl_isNeedLine;

@property (nonatomic, assign) BOOL cl_isNeedSelectedLine;

@property (nonatomic, getter=currentIndex) NSInteger cl_currentIndex;

#pragma mark - Tool Bar Separation Style Property
@property (nonatomic, strong) UIColor *cl_separationColor;

@property (nonatomic, assign) CGFloat cl_separationWidth;

#pragma mark - Common Method
- (void)cl_reloadData;

- (void)cl_didSelectedButton:(NSInteger)index;

@property (nonatomic, copy) void(^cl_toolBarSelectedBlock)(NSInteger index);

关于 CLToolBarListView 的用法, 以前就写过一篇文章, 大家可以去看看 玩转iOS开发:横向滑动条《CLToolBarListView》 .

CLViewController@

CLViewController 是对系统 UIViewController 的封装并添加了一些特性:

typedef NS_ENUM(NSInteger, CLViewControllerStyle) {
    
    CLMainViewController = 0, // Default
    CLChildViewController
};

- (instancetype)initCLViewControllerWith:(CLViewControllerStyle)style;

CLViewControllerViewModel@

CLViewControllerViewModel 是对系统 CLViewController ViewModel , 需要配合使用:

@property (nonatomic, weak, readonly) CLViewController *cl_viewController;

- (instancetype)initViewControllerViewModelWithController:(CLViewController *)controller;

UIApplication+CLApplication@

针对 UIKit UIApplication 进行系统外的方法补充:

+ (BOOL)cl_getApplicationLocationPermit;

+ (BOOL)cl_getApplicationAddressBookPermit;

+ (BOOL)cl_getApplicationCameraPermit;

+ (BOOL)cl_getApplicationRemindersPermit;

+ (BOOL)cl_getApplicationPhotosLibraryPermit;

+ (void)cl_getApplicationMicrophonePermitWithBlock:(CLPermissionBlock)block;

+ (void)cl_callPhoneWithPhoneNumber:(NSString *)phoneNumber;

+ (void)cl_sendEmailWithEmailAddress:(NSString *)emailAddress;

+ (UIImage *)cl_getApplicationLaunchImage;

UIButton+CLButton@

针对 UIKit UIButton 进行系统外的方法补充:

typedef NS_ENUM(NSInteger, CLButtonStarStyle) {
    CLButtonStarStyleBegin = 0,
    CLButtonStarStyleFinish
};

typedef void(^CLButtonStar)(UIButton *cl_starButton, CLButtonStarStyle cl_buttonStarStyle, NSInteger time);

typedef void (^CLButtonAction)(UIButton *sender);

@property (nonatomic, assign) UIEdgeInsets cl_clickAreaEdgeInsets;

@property (nonatomic, assign, readonly) BOOL cl_isSubmitting;

- (void)cl_starButtonWithTime:(NSInteger)time
                     complete:(CLButtonStar)complete;

- (void)cl_addButtonActionComplete:(CLButtonAction)complete;

- (void)cl_showActivityIndicatorViewWithStyle:(UIActivityIndicatorViewStyle)style;

- (void)cl_hideActivityIndicatorView;

- (void)cl_setNormalButtonWithImage:(UIImage *)image;

- (void)cl_setHighlightedButtonWithImage:(UIImage *)image;

- (void)cl_setSelectedButtonWithImage:(UIImage *)image;

- (void)cl_setDisabledButtonWithImage:(UIImage *)image;

- (UIImage *)cl_getNormalButtonImage;

- (UIImage *)cl_getHighlightedButtonImage;

- (UIImage *)cl_getSelectedButtonImage;

- (UIImage *)cl_getDisabledButtonImage;

UICollectionView+CLCollectionView@

针对 UIKit UICollectionView 进行系统外的方法补充:

UICollectionView占位图代理@

@protocol CLCollectionViewPlaceholderDelegate <NSObject>

@required

- (UIView *)cl_placeholderView;

@optional

- (BOOL)cl_scrollEnabledWithShowPlaceholderView;

@end

UICollectionView刷新@

- (void)cl_reloadData;

- (void)cl_removePlaceholderViewWithSuperView;

UIColor+CLColor@

针对 UIKit UIColor 进行系统外的方法补充:

+ (UIColor *)cl_getARC4RandomColor;

+ (UIColor *)cl_colorWithHex:(NSInteger)hexValue;

+ (UIColor *)cl_colorWithHex:(NSInteger)hexValue
                       alpha:(CGFloat)alphaValue;

+ (UIColor *)cl_colorWithHexString:(NSString *)hexString;

+ (UIColor *)cl_colorWithHexString:(NSString *)hexString
                             alpha:(CGFloat)alphaValue;

+ (UIColor *)cl_colorWithRed:(CGFloat)red
                       green:(CGFloat)green
                        blue:(CGFloat)blue
                       alpha:(CGFloat)alpha;

+ (UIColor *)cl_colorWithRed:(CGFloat)red
                       green:(CGFloat)green
                        blue:(CGFloat)blue;

+ (UIColor *)cl_configGradientWithBeginColor:(UIColor *)beginColor
                                    endColor:(UIColor *)endColor
                                      height:(CGFloat)height;

UIControl+CLControl@

针对 UIKit UIControl 进行系统外的方法补充:

typedef void(^CLControlAction)(id sender);

@interface CLControlActionBlockObject : NSObject

@property (nonatomic, copy) CLControlAction cl_controlAction;

@property (nonatomic, assign) UIControlEvents cl_controlEvents;

- (void)cl_controlInvokeBlock:(id)sender;

@end

@interface UIControl (CLControl)

- (void)cl_addControlActionWithEvents:(UIControlEvents)controlEvents
                             complete:(CLControlAction)complete;

- (void)cl_removeControlActionWithEvents:(UIControlEvents)controlEvents;

@end

UIDevice+CLDevice@

针对 UIKit UIDevice 进行系统外的方法补充:

设备相关@

+ (NSString *)cl_getSystemVersion;

+ (NSString *)cl_getDeviceName;

+ (NSString *)cl_getDeviceModelType;

+ (NSString *)cl_getUUIDString;

+ (NSString *)cl_getCurrentDeviceModelName;

CPU相关@

+ (NSUInteger)cl_getCurrentDeviceCPUCount;

+ (CGFloat)cl_getCurrentDeviceAllCoreCPUUse;

+ (NSArray *)cl_getCurrentDeviceSingleCoreCPUUse;

网络相关@

+ (NSString *)cl_getCarrierName;

+ (NSString *)cl_getCurrentRadioAccessTechnology;

+ (NSString *)cl_getCurrentDeviceIPAddresses;

+ (NSString *)cl_getCurrentDeviceIPAddressWithWiFi;

+ (NSString *)cl_getCurrentDeviceIPAddressWithCell;

UIFont+CLFont@

针对 UIKit UIFont 进行系统外的方法补充:

+ (UIFont *)cl_fitSystemFontOfSize:(CGFloat)fontSize;

+ (UIFont *)cl_fitBoldSystemFontOfSize:(CGFloat)fontSize;

+ (UIFont *)cl_fitItalicSystemFontOfSize:(CGFloat)fontSize;

+ (UIFont *)cl_fitSystemFontOfSize:(CGFloat)fontSize
                            weight:(UIFontWeight)weight NS_AVAILABLE_IOS(8_2);

+ (UIFont *)cl_fitMonospacedDigitSystemFontOfSize:(CGFloat)fontSize
                                           weight:(UIFontWeight)weight NS_AVAILABLE_IOS(9_0);

UIImage+CLImage@

针对 UIKit UIImage 进行系统外的方法补充:

生成指定颜色的图片@

+ (void)cl_asyncGetImageWithColor:(UIColor *)color
                       completion:(CLImage)completion;

+ (void)cl_asyncGetImageWithColor:(UIColor *)color
                             rect:(CGRect)rect
                       completion:(CLImage)completion;

+ (void)cl_asyncGetImageWithColor:(UIColor *)color
                           radius:(CGFloat)radius
                       completion:(CLImage)completion;

+ (void)cl_asyncGetImageWithColor:(UIColor *)color
                             rect:(CGRect)rect
                           radius:(CGFloat)radius
                       completion:(CLImage)completion;

截取指定视图大小的截图@

+ (UIImage *)cl_getImageForView:(UIView *)view;

缩放指定比例的图片@

+ (void)cl_asyncDrawImageToSize:(CGSize)size
                          image:(UIImage *)image
                     completion:(CLImage)completion;

加载GIF图片@

+ (void)cl_asyncLoadGIFImageForName:(NSString *)name
                         completion:(CLImage)completion;

+ (void)cl_asyncLoadGIFImageWithData:(NSData *)data
                          completion:(CLImage)completion;

生成二维码@

+ (void)cl_asyncCreateQRCodeImageWithString:(NSString *)string
                                 completion:(CLImage)completion;

+ (void)cl_asyncCreateQRCodeImageWithString:(NSString *)string
                                  logoImage:(UIImage *)logoImage
                                 completion:(CLImage)completion;

生成条形码@

+ (void)cl_asyncCreate128BarcodeImageWithString:(NSString *)string
                                     completion:(CLImage)completion;

+ (void)cl_asyncCreate128BarcodeImageWithString:(NSString *)string
                                     imageSpace:(CGFloat)imageSpace
                                     completion:(CLImage)completion;

获取指定Bundle文件里的图片@

+ (UIImage *)cl_getImageWithBundleName:(NSString *)bundle
                             imageName:(NSString *)imageName;

图片高斯模糊处理@

+ (void)cl_asyncBlurImageWithBlur:(CGFloat)blur
                            image:(UIImage *)image
                       completion:(CLImage)completion;

图片圆角处理@

+ (void)cl_asyncCornerImageWithRadius:(CGFloat)radius
                                image:(UIImage *)image
                           completion:(CLImage)completion;

+ (void)cl_asyncCornerImageWithRadius:(CGFloat)radius
                                image:(UIImage *)image
                          borderWidth:(CGFloat)borderWidth
                          borderColor:(UIColor *)borderColor
                           completion:(CLImage)completion;

图片处理

+ (void)cl_resetSizeWithImage:(UIImage *)image
                         size:(CGSize)size
                   completion:(CLImage)completion;

+ (CGSize)cl_getScaleImageWithImage:(UIImage *)image
                             length:(CGFloat)length;

UINavigationController+CLNavigationController

针对 UIKit UINavigationController 进行系统外的方法补充:







请到「今天看啥」查看全文