帮我分析一下下面的自定义,我想用这个当我的侧边栏收起按钮://
// TPBButton.h
// MacVms
//
// Created by LSL on 2/17/25.
//
#import <Foundation/Foundation.h>
#import "TPBDesign.h"
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, TPBButtonStyle) {
/// 默认,圆角矩形,radius为TPBDesign.button.roundRectCornerRadius
TPBButtonStyleRoundRect = 0,
/// 圆角,radius为height的一半
TPBButtonStyleOval,
/// iOS系统样式,无圆角
TPBButtonStyleSquare,
};
// 按钮当前交互状态,用于管理样式表现
typedef NS_ENUM(NSInteger, TPBButtonStatus) {
/// 默认状态
TPBButtonStatusNormal,
/// 悬浮状态
TPBButtonStatusHover,
};
typedef void(^TPBButtonStatusChangeCallback)(TPBButtonStatus status);
@class TPBButton;
@interface TPBButton : TPBBaseControl
/// 按钮边框样式
@property (nonatomic, assign) TPBButtonStyle style;
/// 设置Loading时是否禁用按钮
@property (nonatomic, assign) BOOL isEnabledWhenLoading;
/// 按钮圆角,如果设置该值且值大于0,则会覆盖按钮样式的默认值
@property (nonatomic, assign) CGFloat cornerRadius;
/// 按钮四周是否有填充
@property (nonatomic, assign) CGFloat hasPadding;
/// 按钮Title
@property (nonatomic, nullable, copy) NSString *title;
/// 按钮Title字体
@property (nonatomic, nullable, strong) NSFont *titleFont;
/// 边框颜色
@property (nonatomic, nullable, strong) NSColor *strokeColor;
/// 按钮是否能触发选中
@property (nonatomic, assign) BOOL selectable;
/// 按钮当前是否被选中(selectable = yes时才生效,否则恒为NO)
@property (nonatomic, assign) BOOL selected;
/* 各种状态下的图标、文字颜色、背景色设置 */
/// 按钮Title颜色
@property (nonatomic, nullable, strong) NSColor *titleColor;
/// 按钮图标
@property (nonatomic, nullable, strong) NSImage *iconImage;
/// 按钮背景色
@property (nonatomic, nullable, strong) NSColor *fillColor;
/// loading动画的颜色
@property (nonatomic, nullable, strong) NSColor *loadingColor;
/// 禁用时图标
@property (nonatomic, nullable, strong) NSImage *disableIconImage;
/// 禁用时图标色
@property (nonatomic, nullable, strong) NSColor *disableIconImageColor;
/// 禁用背景色
@property (nonatomic, nullable, strong) NSColor *disableFillColor;
/// 禁用文字色
@property (nonatomic, nullable, strong) NSColor *disableTitleColor;
/// 悬浮时图标
@property (nonatomic, nullable, strong) NSImage *hoverIconImage;
/// 悬浮时图标色
@property (nonatomic, nullable, strong) NSColor *hoverIconImageColor;
/// 悬浮时文字色
@property (nonatomic, nullable, strong) NSColor *hoverTitleColor;
/// 悬浮时按钮颜色
@property (nonatomic, nullable, strong) NSColor *hoverColor;
/// 选中时图标
@property (nonatomic, nullable, strong) NSImage *selectedIconImage;
/// 选中时图标色
@property (nonatomic, nullable, strong) NSColor *selectedIconImageColor;
/// 选中时文字色
@property (nonatomic, nullable, strong) NSColor *selectedTitleColor;
/// 选中时按钮颜色
@property (nonatomic, nullable, strong) NSColor *selectedFillColor;
/// 点击事件回调
@property (nonatomic, nullable, copy) TPBAppVoidCallback onClickCallback;
@property (nonatomic, nullable, copy) void(^onClickCallWithEvent)(NSEvent *);
/// 状态改变回调
@property (nonatomic, nullable, copy) TPBButtonStatusChangeCallback statusChangeCallback;
@property (nonatomic, nullable, copy) TPBButtonStatusChangeCallback focusChangeBlk;
/// 返回按钮当前是否是加载状态
@property (nonatomic, readonly, assign) BOOL isLoading;
- (instancetype)init;
- (instancetype)initWithStyle:(TPBButtonStyle)style;
- (instancetype)initWithStyle:(TPBButtonStyle)style title:(nullable NSString *)title;
+ (instancetype)buttonWithStyle:(TPBButtonStyle)style;
+ (instancetype)buttonWithStyle:(TPBButtonStyle)style title:(nullable NSString *)title;
/// 进入Loading状态
- (void)startLoading;
/// 退出Loading状态
- (void)stopLoading;
@end
@interface TPBButton (TPBExpanded)
/// 纯文字按钮
+ (TPBButton *)cardButtonWithTitle:(nullable NSString *)title;
/// 纯图标按钮
+ (TPBButton *)iconButtonWithImage:(nullable NSImage *)image;
/// 文字 + 边框按钮
+ (TPBButton *)lineButtonWithTitle:(nullable NSString *)title;
@end
NS_ASSUME_NONNULL_END
最新发布