Files
featherVoice/QXLive/Tools/Category/UIView+QX.h

159 lines
5.1 KiB
C
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// UIView+QX.h
// QXLive
//
// Created by 启星 on 2025/4/27.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger , ShadowPathType) {
ShadowPathTop = 1,
ShadowPathBottom = 2,
ShadowPathLeft = 3,
ShadowPathRight = 4,
ShadowPathCommon = 5,
ShadowPathAround = 6,
};
typedef NS_ENUM(NSUInteger, SRGradientDirection) {
SRGradientDirectionTopToBottom, // 渐变色从上到下
SRGradientDirectionLeftToRight, // 渐变色从左到右
};
@interface UIView (QX)
/** 起点x坐标 */
@property (nonatomic, assign) CGFloat x;
/** 起点y坐标 */
@property (nonatomic, assign) CGFloat y;
/** 中心点x坐标 */
@property (nonatomic, assign) CGFloat centerX;
/** 中心点y坐标 */
@property (nonatomic, assign) CGFloat centerY;
/** 宽度 */
@property (nonatomic, assign) CGFloat width;
/** 高度 */
@property (nonatomic, assign) CGFloat height;
/** 顶部 */
@property (nonatomic, assign) CGFloat top;
/** 底部 */
@property (nonatomic, assign) CGFloat bottom;
/** 左边 */
@property (nonatomic, assign) CGFloat left;
/** 右边 */
@property (nonatomic, assign) CGFloat right;
/** size */
@property (nonatomic, assign) CGSize size;
/** origin */
@property (nonatomic, assign) CGPoint origin;
/**
View添加4边阴影
:0
*/
- (void)addProjectionWithShadowOpacity:(CGFloat)shadowOpacity;
/**
View添加4边阴影
*/
- (void)addShadowWithColor:(UIColor*)color radius:(CGFloat)radius;
- (void)addShadowWithColor:(UIColor*)color radius:(CGFloat)radius frame:(CGRect)frame;
/**
View添加4边框
:
*/
- (void)addBorderWithWidth:(CGFloat)width;
/**
View添加4边框
width:
borderColor:
*/
- (void)addBorderWithWidth:(CGFloat)width borderColor:(UIColor *)borderColor;
/**
View添加圆角
:
*/
- (void)addRoundedCornersWithRadius:(CGFloat)radius;
/**
View添加圆角
radius:
corners:
:
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft,
UIRectCornerTopRight ,
UIRectCornerBottomLeft,
UIRectCornerBottomRight,
UIRectCornerAllCorners
};
使:[self.mainView addRoundedCornersWithRadius:10 byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight]; // 切除了左下 右下
*/
- (void)addRoundedCornersWithRadius:(CGFloat)radius byRoundingCorners:(UIRectCorner)corners;
/************** 按自身Bounds计算 *************/
- (void)setTopToBottomGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors;
- (void)setLeftToRightGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors;
- (void)setGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint;
- (void)setLeftToRightGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors roundedCorners:(CGFloat)radius;
- (void)setAroundRoundedCorners:(CGFloat)radius;
- (void)setTopRoundedCorners:(CGFloat)radius;
- (void)setBottomRoundedCorners:(CGFloat)radius;
- (void)setLeftRoundedCorners:(CGFloat)radius;
/************* 按Frame计算 *************/
/** 设置渐变色 */
- (void)setViewBackgroundColorWithColorArray:(NSArray *)colorArray scaleArray:(NSArray * __nullable)scaleArray direction:(SRGradientDirection)direction;
/** 仅设置由上至下的渐变色 */
- (void)setTopToBottomGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors frame:(CGRect)frame;
/** 仅设置由左至右的渐变色 */
- (void)setLeftToRightGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors frame:(CGRect)frame;
/** 仅设置自定义起始和结束位置的渐变色 */
- (void)setGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint frame:(CGRect)frame;
/** 设置由左至右的圆角渐变色 */
- (void)setLeftToRightGradientBackgroundWithColors:(NSArray<UIColor *> *_Nullable)colors roundedCorners:(CGFloat)radius frame:(CGRect)frame;
/** 仅设置裁剪 */
- (void)setAroundRoundedCorners:(CGFloat)radius frame:(CGRect)frame;
/** 仅设置顶部角裁剪 */
- (void)setTopRoundedCorners:(CGFloat)radius frame:(CGRect)frame;
/** 仅设置底部角裁剪 */
- (void)setBottomRoundedCorners:(CGFloat)radius frame:(CGRect)frame;
/** 仅设置左侧角裁剪 */
- (void)setLeftRoundedCorners:(CGFloat)radius frame:(CGRect)frame;
/**
UIView添加阴影
@param shadowColor
@param shadowOpacity 0
@param shadowRadius 3
@param shadowPathType
@param shadowPathWidth g宽度
*/
- (void)setViewShadowPathWithColor:(UIColor *)shadowColor shadowOpacity:(CGFloat)shadowOpacity shadowRadius:(CGFloat)shadowRadius shadowPathType:(ShadowPathType)shadowPathType shadowPathWidth:(CGFloat)shadowPathWidth;
- (void)addTapBlock:(void(^)(id obj))tapAction;
- (UIViewController *)viewController;
- (UINavigationController *)navigationController;
@end
NS_ASSUME_NONNULL_END