文档

异常页组件

更新时间:

AUNetErrorView 为空页面异常视图显示控件,包括以下两种提示风格。

  • 简单版(半屏)风格,包含 5 种样式,为默认风格。

  • 插图版(全屏)风格,包含 5 种样式。

两种风格的主要区别在于使用的提示图片不同,见效果图。

效果图

  • 简单版(半屏)风格

    image
  • 插图版(全屏)风格image

接口说明

    typedef NS_ENUM(NSInteger, AUNetErrorType) {

    AUNetErrorTypeLimit,        // 限流
    AUNetErrorTypeAlert,        // 系统繁忙(系统错误)、警示
    AUNetErrorTypeNetworkError, // 网络错误
    AUNetErrorTypeEmpty,        // 内容为空
    AUNetErrorTypeNotFound,     // 404 找不到(与 AUNetErrorTypeAlert 图片相同)
    AUNetErrorTypeUserLogout,   // 用户已注销

    AUNetErrorTypeFailure __attribute__((deprecated)) = AUNetErrorTypeNetworkError,
    AUNetErrorTypeError __attribute__((deprecated)) = AUNetErrorTypeNetworkError,             //网络错误,完全无法连接
    AUNetErrorTypeSystemBusy __attribute__((deprecated)) = AUNetErrorTypeAlert,               //警示
    APExceptionEnumNetworkError __attribute__((deprecated)) = AUNetErrorTypeNetworkError,     //网络错误,完全无法连接
    APExceptionEnumEmpty __attribute__((deprecated)) = AUNetErrorTypeEmpty,                   //内容为空
    APExceptionEnumAlert __attribute__((deprecated)) = AUNetErrorTypeAlert,                   //警示
    APExceptionEnumLimit __attribute__((deprecated)) = AUNetErrorTypeLimit,                   //限流,
    APExceptionEnumNetworkFailure __attribute__((deprecated)) =  AUNetErrorTypeNetworkError,  //网络错误
};


typedef NS_ENUM(NSInteger, AUNetErrorStyle) {
    AUNetErrorStyleMinimalist,    //简单版
    AUNetErrorStyleIlustration,   //插图版

    APExceptionStyleIlustration __attribute__((deprecated)) = AUNetErrorStyleIlustration,     //插图版
    APExceptionStyleMinimalist __attribute__((deprecated)) =  AUNetErrorStyleMinimalist       //简单版
};
    /**
     空页面异常视图显示控件

     包括两种提示风格:
            1、简单版风格(默认),包含 3 种类型样式
            2、插图版风格,包含 7 种类型样式

     两种风格和类型主要是图片不一样。
     */
    @interface AUNetErrorView : UIView

    @property(nonatomic, strong, readonly) UIButton *actionButton;      // 默认文案是刷新
    @property(nonatomic, strong, readonly) UIImageView *iconImageView;  // icon 视图
    @property(nonatomic, strong, readonly) UILabel *infoLabel;          // 主提示文案 Label
    @property(nonatomic, strong, readonly) UILabel *detailLabel;        // 详细提示文案 Label

    @property(nonatomic, strong) NSString *infoTitle;                   // 主文案说明
    @property(nonatomic, strong) NSString *detailTitle;                 // 辅助文案说明

    /**
     *  初始化异常 view 并设定异常风格和类型
     *  (target 和 action 为空时,刷新按钮不显示)
     *
     *  @param frame    view 的坐标,必选
     *  @param style    异常的风格,插画版 or 极简版,必选
     *  @param type     异常类型,必选
     *  @param target   刷新事件处理对象
     *  @param action   刷新事件处理方法
     *
     *  @return APExceptionView
     */
    - (id)initWithFrame:(CGRect)frame
                                style:(AUNetErrorStyle)style
                                type:(AUNetErrorType)type
                            target:(id)target
                            action:(SEL)action;

    /**
     *  初始化异常视图并显示在指定的视图上
     *  (target 和 action 为空时,刷新按钮不显示)
     *
     *  @param parent view 的 superView,必选
     *  @param style  异常的风格,插画版 or 极简版,必选
     *  @param type   异常类型,必选
     *  @param target 刷新事件处理对象
     *  @param action 刷新事件处理方法
     *
     *  @return APExceptionView
     */
    + (id)showInView:(UIView *)parent
                        style:(AUNetErrorStyle)style
                        type:(AUNetErrorType)type
                        target:(id)target
                        action:(SEL)action;

    /**
     * 取消异常视图的显示
     */
    - (void)dismiss;

    /**
 *  倒计时,仅限限流使用
 *  如果 completeBlock == nil 且 业务没有设置 actionButton 的点击响应事件,则倒计时功能不生效;
 *  如果 completeBlock != nil,倒计时结束直接执行 completeBlock,同时隐藏 actionButton
 *  如果使用 getActionButton 来添加 button 的响应事件,要确保在该方法之前添加 actionButton 的响应事件
 */
- (void)setCountdownTimeInterval:(NSInteger)startTime  // 倒计时起始时间
                   completeBlock:(void (^)(void))completeBlock; // 倒计时结束后

    @end

代码示例

    netErrorView = [[AUNetErrorView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame) + 5, self.view.width, 300) style:AUNetErrorStyleIlustration type:AUNetErrorTypeError target:self action:@selector(pressedNetErrorView)];
    netErrorView.detailTitle = @"类型是AUNetErrorTypeError";
    [self.view addSubview:netErrorView];

    // 设置倒计时
    [netErrorView setCountdownTimeInterval:10 completeBlock:^{
            NSLog(@"倒计时结束");
    }];
  • 本页导读 (0)
文档反馈