基础库梳理二

基础库UI及说明

首先结构如下图所示:

这里分成三层:

  • 公共设置common层
  • 核心core层
  • 公共方法PublicMethods层

关于数据层主要跟随业务进行数据处理的封装,这里不做描述,后续根据自己的情况进行对应的添加补充,下面主要是进行UI结构上的说明。


common层

FGCategoryUtility
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/// 设定视图四个角其中一个的数据结构
struct FGCorner {
UIRectCorner cornerType; ///< The type of corner.
CGFloat radius; ///< The radius of corner.
};
typedef struct FGCorner FGCorner;

/// 设定视图阴影
struct FGShadow {
CGColorRef color; ///< The color of shadow.
CGSize offset; ///< The shadow offset.
CGFloat opacity; ///< The opacity of the shadow.
CGFloat radius; ///< The radius of the shadow.
};
typedef struct FGShadow FGShadow;

///设定边框
struct FGBorder {
CGColorRef color; ///< The color of bolder.
CGFloat width; ///< The width of bolder.
};
typedef struct FGBorder FGBorder;

///以下是各个数据结构的内联构造函数
/*!
@abstract Get main screen's scale.
*/
static inline CGFloat FGScreenScale() {
return [UIScreen mainScreen].scale;
};

/*!
@abstract Get main screen's size.
*/
static inline CGSize FGScreenSize() {
return [UIScreen mainScreen].bounds.size;
};

/*!
@abstract Describe the layer shadow.
*/
static inline FGShadow FGShadowMake(CGColorRef color, CGSize offset, CGFloat radius, CGFloat opacity) {
FGShadow shadow;
shadow.color = color;
shadow.offset = offset;
shadow.radius = radius;
shadow.opacity = opacity;
return shadow;
}

/*!
@abstract Describe the layer bolder.
*/
static inline FGBorder FGBorderMake(CGColorRef color, CGFloat width) {
FGBorder border;
border.color = color;
border.width = width;
return border;
}

/*!
@abstract Describe the layer corner.
*/
static inline FGCorner FGCornerMake(UIRectCorner cornerType, CGFloat radius) {
FGCorner corner;
corner.cornerType = cornerType;
corner.radius = radius;
return corner;
}

/*!
@abstract Convert point to pixel.
*/
static inline CGFloat FGFloatToPixel(CGFloat value) {
return value * FGScreenScale();
}

/*!
@abstract Convert pixel to point.
*/
static inline CGFloat FGFloatFromPixel(CGFloat value) {
return value / FGScreenScale();
}


FGCategoryMacro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
///宏定义函数,简化联结对象设置
#ifndef FGSYNTH_DUMMY_CLASS
#define FGSYNTH_DUMMY_CLASS(_name_) \
@interface FGSYNTH_DUMMY_CLASS ## _name_ : NSObject @end \
@implementation FGSYNTH_DUMMY_CLASS ## _name_ @end
#endif

#ifndef FG_DYNAMIC_PROPERTY_OBJECT
#define FG_DYNAMIC_PROPERTY_OBJECT(_getter_, _setter_, _association_, _type_) \
- (void)_setter_ : (_type_)object { \
[self willChangeValueForKey:@#_getter_]; \
objc_setAssociatedObject(self, _cmd, object, OBJC_ASSOCIATION_ ## _association_); \
[self didChangeValueForKey:@#_getter_]; \
} \
- (_type_)_getter_ { \
return objc_getAssociatedObject(self, @selector(_setter_:)); \
}
#endif

#ifndef FG_DYNAMIC_PROPERTY_CTYPE
#define FG_DYNAMIC_PROPERTY_CTYPE(_getter_, _setter_, _type_) \
- (void)_setter_ : (_type_)object { \
[self willChangeValueForKey:@#_getter_]; \
NSValue *value = [NSValue value:&object withObjCType:@encode(_type_)]; \
objc_setAssociatedObject(self, _cmd, value, OBJC_ASSOCIATION_RETAIN); \
[self didChangeValueForKey:@#_getter_]; \
} \
- (_type_)_getter_ { \
_type_ cValue = { 0 }; \
NSValue *value = objc_getAssociatedObject(self, @selector(_setter_:)); \
[value getValue:&cValue]; \
return cValue; \
}
#endif

core层

UIViewController+FGAutorotate
1
2
3
4
///控制器旋转属性
@property (nonatomic) BOOL shouldAutorotate;
@property (nonatomic) UIInterfaceOrientationMask supportedInterfaceOrientations;
@property (nonatomic) UIInterfaceOrientation preferredInterfaceOrientationForPresentation;

FGModalViewController: QMUIModalPresentationViewController
1
2
3
4
5
6
7
8
/// 快速创建一个从下往上弹出的modalView
/// @param contentView 内容View
- (instancetype)initWithContentView:(UIView *)contentView;

/// 快速创建一个从下往上弹出的modalView 并添加到window上
/// @param contentView 内容视图
/// @param onClickDimmingBlock 点击背景回调方法
+ (void)fg_showModalView:(UIView *)contentView inView:(UIView *)superView onClickDimmingBlock:(void(^)(void))onClickDimmingBlock;

FGNavigationBarBackground : UIView
1
2
3
4
@property (nonatomic, assign) FGShadow barShade UI_APPEARANCE_SELECTOR; ///< 阴影
@property (nonatomic, assign) BOOL barShadeHidden UI_APPEARANCE_SELECTOR; ///< 是否隐藏阴影, 默认NO
@property (nonatomic, strong, nullable) UIImage *backgroundImage UI_APPEARANCE_SELECTOR; ///< 背景图片
@property (nonatomic, strong, nullable) UIColor *barTintColor UI_APPEARANCE_SELECTOR; ///< 背景色

UI_APPEARANCE_SELECTOR是系统开关宏,作用是一次性全局统一设置,设置后便不再改变。


FGBaseNavigationViewController : QMUINavigationController
1
@property (nonatomic, strong, readonly) FGNavigationBarBackground *navigationBarBackground;//导航栏背景视图,用于处理导航栏状态不一致时瞬间的变化

FGPickerViewController : QMUIModalPresentationViewController
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
typedef void(^FGPickerSelectedBlock)(NSString *content , NSInteger selectedIndex);
typedef void(^FGPickerCancelBlock)(void);

@property (nonatomic, strong) UILabel *titleLabel; //标题
@property (nonatomic, strong) UIButton *cancelButton; //取消按钮
@property (nonatomic, strong) UIButton *sureButton; //确定按钮
/**
展示一级picker控件
@param title 标题
@param dataSource 数据源
@param selectedIndex 默认选中下标
@param animation 是否动画
@param complete 选择完成确定
@param cancel 取消选择
*/
+ (void)fg_showPickerWithTitle:(NSString *)title
dataSource:(NSArray <NSString *>*)dataSource
defaultSelectedIndex:(NSInteger)selectedIndex
defaultSelectedAnimation:(BOOL)animation
selected:(FGPickerSelectedBlock)complete
cancel:(FGPickerCancelBlock)cancel;

FGBaseTabbarViewController : QMUITabBarViewController
FGBaseTableViewController : QMUICommonTableViewController
FGBaseViewController : QMUICommonViewController

这里的tabbarVC/tableVC/baseVC都是基于qmui构建,做了一层隔离扩展,一方面是可以重写qmui里面的方法,另外也可以做到无缝替换。


PublicMethods层

UIAlertController+FGBlocks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/// 弹出alert/actionsheet
/// @param viewController 当前控制器
/// @param title 标题
/// @param message 内容
/// @param preferredStyle 弹出方式
/// @param cancelButtonTitle 取消按钮标题
/// @param destructiveButtonTitle 作用按钮标题
/// @param otherButtonTitles 附加按钮标题
/// @param popoverPresentationControllerBlock 气泡菜单回调
/// @param tapBlock 按钮点击回调
+ (nonnull instancetype)fg_showInViewController:(nonnull UIViewController *)viewController
withTitle:(nullable NSString *)title
message:(nullable NSString *)message
preferredStyle:(UIAlertControllerStyle)preferredStyle
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle
otherButtonTitles:(nullable NSArray *)otherButtonTitles
#if TARGET_OS_IOS
popoverPresentationControllerBlock:(nullable UIAlertControllerPopoverPresentationControllerBlock)popoverPresentationControllerBlock
#endif
tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;


/// 弹出alert
/// @param viewController 当前控制器
/// @param title 标题
/// @param message 内容
/// @param cancelButtonTitle 取消按钮标题
/// @param destructiveButtonTitle 作用按钮标题
/// @param otherButtonTitles 附加按钮标题
/// @param tapBlock 按钮点击回调
+ (nonnull instancetype)fg_showAlertInViewController:(nonnull UIViewController *)viewController
withTitle:(nullable NSString *)title
message:(nullable NSString *)message
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle
otherButtonTitles:(nullable NSArray *)otherButtonTitles
tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;



/// 弹出actionsheet
/// @param viewController 当前控制器
/// @param title 标题
/// @param message 内容
/// @param cancelButtonTitle 取消按钮标题
/// @param destructiveButtonTitle 作用按钮标题
/// @param otherButtonTitles 附加按钮标题
/// @param popoverPresentationControllerBlock 气泡菜单回调
/// @param tapBlock 按钮点击回调
+ (nonnull instancetype)fg_showActionSheetInViewController:(nonnull UIViewController *)viewController
withTitle:(nullable NSString *)title
message:(nullable NSString *)message
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle
otherButtonTitles:(nullable NSArray *)otherButtonTitles
#if TARGET_OS_IOS
popoverPresentationControllerBlock:(nullable UIAlertControllerPopoverPresentationControllerBlock)popoverPresentationControllerBlock
#endif
tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;


@property (readonly, nonatomic) BOOL visible; //是否可视
@property (readonly, nonatomic) NSInteger cancelButtonIndex; //取消索引
@property (readonly, nonatomic) NSInteger firstOtherButtonIndex; //第一个附加按钮索引
@property (readonly, nonatomic) NSInteger destructiveButtonIndex; //动作按钮索引

UIBarButtonItem+FGBuildObject
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
+ (instancetype)fg_itemWithImage:(id)image
offset:(CGFloat)offset
target:(nullable id)target
action:(nullable SEL)action;

+ (instancetype)fg_itemWithImage:(id)image
highlightedColor:(nullable UIColor *)highlightedColor
offset:(CGFloat)offset
target:(nullable id)target
action:(nullable SEL)action;

+ (instancetype)fg_itemWithTitle:(NSString *)title
target:(nullable id)target
action:(nullable SEL)action;

+ (instancetype)fg_itemWithTitle:(NSString *)title
offset:(CGFloat)offset
target:(nullable id)target
action:(nullable SEL)action;

+ (instancetype)fg_itemWithTitle:(NSString *)title
normalAttributes:(nullable NSDictionary *)normalAttributes
highlightedAttributes:(nullable NSDictionary *)highlightedAttributes
offset:(CGFloat)offset
target:(nullable id)target
action:(nullable SEL)action;

UIBarButtonItem的附加构造方法,加入了高亮色highlightedColor以及offset图片水平偏移的设置


UIButton+FGLoading
1
2
3
4
5
/// 开始加载
- (void)fg_startLoading;

/// 结束加载
- (void)fg_stopLoading;

UICollectionViewCell+FGAdditions
1
2
3
4
5
6
7
8
9
//内层底部视图
@property (nonatomic, strong) UIView *insertsView;
//获取重用cellId
+ (NSString *)fg_cellId;
/// 内层构建约束
/// @param edge 内边距
- (void)fg_createInsertsView:(UIEdgeInsets)edge;
//允许cell提供高度设置
+ (CGSize)fg_dynamicSizeCell;

UIImage+FGUtilities
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*!
@abstract Return the image object associated with the specified filename.
@param resource The name of file.
@result An UIImage object, or nil if no resource or error resource.
@discussion
This method loads the image data from the specified file, but not caches it.
*/
+ (nullable UIImage *)fg_imageWithResource:(NSString *)resource;

/*!
@abstract Return the animated image object associated with the specified filename.
@param resource The name of file.
@result An UIImage object, or nil if no resource or error resource.
*/
+ (nullable UIImage *)fg_animatedImageWithResource:(NSString *)resource;

/**
压缩图片 限制图片的最大长边的长度为newImageWidth

@param image 图片
@param newImageWidth 最大长边值
@return 裁剪后的新图片
*/
+ (UIImage *)fg_compressImage:(UIImage *)image newWidth:(CGFloat)newImageWidth;

/**
压缩长图 限制图片的最小长边的长度为newImageWidth

长图: 宽>=长*2 或者 长>=宽*2

@param image 图片
@param newImageWidth 最大长边值
@return 裁剪后的新图片
*/
+ (UIImage *) fg_compressLongImage:(UIImage *)image newWidth:(CGFloat)newImageWidth;

/**
是否为长图

长图: 宽>=长*2 或者 长>=宽*2

@return return value description
*/
- (BOOL) fg_isLongImage;


/// 将原图片按照size绘制
/// @param image 原图
/// @param size 目的size
+ (UIImage*) fg_originImage:(UIImage *)image scaleToSize:(CGSize)size;

/// 修正图片的方向
- (UIImage *)fg_fixOrientation;

/// 更改图片本身的朝向
/// @param orient 方向
- (UIImage *)fg_rotate:(UIImageOrientation)orient;


/// 图片旋转
/// @param rotate 旋转角度参数
- (UIImage *)fg_rotateAngle:(NSInteger)rotate;

UILabel+FGLoadMutableAttibute
1
2
3
4
5
6
7
/// 加载html
/// @param htmlStr html字符串
- (void)fg_loadHtml:(NSString *)htmlStr;

/// 加载文件html
/// @param filePath 文件路径
- (void)fg_loadHtmlFromFilePath:(NSString *)filePath;

CALayer+FGDrawing/UIView+FGDrawing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// 添加阴影
/// @param shadow 阴影结构数据
- (void)fg_addShadow:(FGShadow)shadow;

/// 添加边框
/// @param border 边框结构数据
- (void)fg_addBorder:(FGBorder)border;

/// 添加圆角
/// @param radius 圆角半径
- (void)fg_addCorner:(CGFloat)radius;

/// 添加边框、圆角
/// @param border 边框结构数据
/// @param radius 圆角结构数据
- (void)fg_addBorder:(FGBorder)border radius:(CGFloat)radius;

UIScrollView+FGMultiply
1
2
3
4
/// 嵌套时是否随着手势生效
@property (nonatomic, strong) NSNumber *recognizeScrollEnable;
//监听滚动停止
@property (nonatomic, copy, nullable) FGMultiplyScrollHandle handle;

UITabBar+FGCustomBadge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
*
*设置tab上icon的宽度,用于调整badge的位置
*/
- (void)fg_setTabIconWidth:(CGFloat)width;

/**
*设置badge的top
*/
- (void)fg_setBadgeTop:(CGFloat)top;

/**
*设置badge样、数字
*/
- (void)fg_setBadgeStyle:(FGSKMCustomBadgeStyleType)type value:(NSInteger)badgeValue atIndex:(NSInteger)index;

/**
清空所有红点视图
*/
- (void)fg_cleanAllBadgeView;

UITabBarItem+FGBuildObject
1
2
3
//附加构建方法
+ (instancetype)fg_itemWithTitle:(nullable NSString *)title image:(nullable NSString *)image tag:(NSInteger)tag;
+ (instancetype)fg_itemWithTitle:(nullable NSString *)title image:(nullable NSString *)image selectedImage:(nullable NSString *)selectedImage;

UITableView+FGWeexTable
1
2
//底部footview隐藏
- (void)fg_hideCellFootView;

UITableViewCell+FGAdditions
1
2
3
4
5
6
7
8
9
10
11
//内层底部视图
@property (nonatomic, strong) UIView *insertsView;
//获取重用cellId
+ (NSString *)fg_cellId;
/// 内层构建约束
/// @param edge 内边距
- (void)fg_createInsertsView:(UIEdgeInsets)edge;

//允许cell提供高度设置
- (CGFloat)fg_dynamicRowHeight:(UITableViewCell *)cell
tableView:(UITableView *)tableView;

UITextField+FGUtilities
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@property (nonatomic, nullable) UIColor *placeholdColor; ///< The color of the placehold.

/*!
@abstract Limit the maximum number of inputs. Emoji is regarded as a unit length.
@param number The maximum number of inputs.
@param autoIntercept Whether needs interception.
@result The number of inputs.
*/
- (NSInteger) fg_limitMaxNumber:(NSInteger)number autoIntercept:(BOOL)autoIntercept;


/// 失去第一响应
+ (void) fg_allResignFirstResponder;

/// 选中范围
- (void) fg_selectTextAtRange:(NSRange)range;

UITextView+FGUtilities
1
2
3
4
5
/// 限制字符长度
/// @param number 长度
/// @param autoIntercept 是否自动打断
- (NSInteger)fg_limitMaxNumber:(NSInteger)number
autoIntercept:(BOOL)autoIntercept;

UIView+FGUtilities
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// 绘制左上右上圆角
/// @param radious 圆角半径
- (void)fg_roundedCornersOnTopWithRadious:(CGFloat)radious;

/// 绘制左上圆角
/// @param radious 圆角半径
- (void)fg_roundedCornersOnTopLeftWithRadious:(CGFloat)radious;

/// 绘制右上圆角
/// @param radious 圆角半径
- (void)fg_roundedCornersOnTopRightWithRadious:(CGFloat)radious;

/// 绘制左下右下圆角
/// @param radious 圆角半径
- (void)fg_roundedCornersOnBottomWithRadious:(CGFloat)radious;

/// 绘制左下圆角
/// @param radious 圆角半径
- (void)fg_roundedCornersOnBottomLeftWithRadious:(CGFloat)radious;

/// 绘制右下圆角
/// @param radious 圆角半径
- (void)fg_roundedCornersOnBottomRightWithRadious:(CGFloat)radious;

/// 绘制全部圆角
/// @param radious 圆角半径
- (void)fg_roundedCornersOnAllSideWithRadious:(CGFloat)radious;

FGViewCreateUtil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//构建UILabel
- (UILabel *)fg_label:(UIFont *)font
color:(UIColor *)color
text:(NSString *)text;

- (UILabel *)fg_label:(UIFont *)font
color:(UIColor *)color
text:(NSString *)text
numerLines:(NSInteger)lines;

- (UILabel *)fg_label:(UIFont *)font
color:(UIColor *)color
text:(NSString *)text
textAligment:(NSTextAlignment)textAlignment
numerLines:(NSInteger)lines;

//构建UIButton
- (UIButton *)fg_btn:(nonnull NSString *)text
font:(nonnull UIFont *)font
color:(nonnull UIColor *)color
backGroundColor:(nonnull UIColor *)backGroundColor;

- (UIButton *)fg_btn:(nonnull NSString *)normalImage
selectedImage:(nullable NSString *)selectedImage;

- (void)fg_btn:(UIButton *)btn
title:(NSString *)title
titleColor:(UIColor *)titleColor
font:(UIFont *)font
normalImage:(NSString *)normalImage;

//构建UITableView
- (UITableView *)fg_tableViewConfig:(id<UITableViewDelegate,UITableViewDataSource>)delegate
style:(UITableViewStyle)style;

//UITableView注册多个UITableViewCell类型
- (void)fg_registerCells:(NSArray *)arr
tableView:(UITableView *)tableView;

- (void)fg_registerCellsDic:(NSDictionary *)dic
tableView:(UITableView *)tableView;

//设置当前滚动视图contentInset不自动调整
- (void)fg_setAutoContentAdjustment:(UIScrollView *)scrollView;

//禁用UITableView的估算行高
- (void)fg_stopTableViewEstimated:(UITableView *)tableView;

//提供手势点击方法
- (void)fg_addTapGesture:(UIView *)view
action:(SEL)action;

WKWebView+FGUtilities
1
2
3
//截图
- (void ) fg_screenFromContentSizeHeight:(float)height
andSnapshot:(void(^)(UIImage *snapShotImage))finishBlock;

这里显示的都是关于UI设置及方法方面的,后续如果存在新增请在对应的分块中进行,并修改podspec文件后再升级。