// // UIView+QX.h // QXLive // // Created by 启星 on 2025/4/27. // #import 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 *_Nullable)colors; - (void)setLeftToRightGradientBackgroundWithColors:(NSArray *_Nullable)colors; - (void)setGradientBackgroundWithColors:(NSArray *_Nullable)colors startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint; - (void)setLeftToRightGradientBackgroundWithColors:(NSArray *_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 *_Nullable)colors frame:(CGRect)frame; /** 仅设置由左至右的渐变色 */ - (void)setLeftToRightGradientBackgroundWithColors:(NSArray *_Nullable)colors frame:(CGRect)frame; /** 仅设置自定义起始和结束位置的渐变色 */ - (void)setGradientBackgroundWithColors:(NSArray *_Nullable)colors startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint frame:(CGRect)frame; /** 设置由左至右的圆角渐变色 */ - (void)setLeftToRightGradientBackgroundWithColors:(NSArray *_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