Handy operating tips for iOS

1. Origin

Why should I repackage MBProgressHUD ? The new job I found this year, the project was created relatively early, the project created in 2014, some operation tips now used in the project, since it is still the first open source I used when I first started working on iOS development Three party toast . It can be said that this open source library is older than my working age, and it is already out of date, and its style is not good-looking, far from MBProgressHUD . So I decided to re-package MBProgressHUD and produce a demo, determined to persuade the product to replace it.

Two, the use of XBLoadingKit

XBLoadingKit mainly encapsulates several commonly used prompts, including success , failure , warning , loading , and long text messages .

1. How to use


- (void)showOperationHudWithStatus:(TipStatus)tipStatus{
    
    switch (tipStatus) {
        case operation_success_status:
            [MBProgressHUD showSuccess:@"操作成功的提示" toView:self.view]; //成功的提示
            break;
        case operation_fail_status:
            [MBProgressHUD showError:@"操作失败的提示" toView:self.view]; //失败提示
            break;
        case operation_warning_status:
            [MBProgressHUD showWarning:@"操作遇到了警告" toView:self.view]; //警告提示
            break;
            
        default:
            break;
    }
}

//网络加载时的loading
- (void)networkLoading{
    
    [MBProgressHUD showMessage:@"loading..." toView:self.view];
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // Do something...
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    });
}

//显示长文本提示
- (void)showLongMessage{
    
    [MBProgressHUD showDetailMessage:@"寂寞空庭春欲晚,梨花满地不开门,昨夜雨疏风骤" toView:self.view delay:2.0];
}

2. Style

XBLoadingKit provides two styles.

  • Off-white background (icon and prompt text are gray)
  • Black background (icon and prompt text are white)
/**
 hud的样式

 - gray_background_style: 灰色背景
 - dim_background_style: 黑色背景
 */
typedef NS_ENUM(NSInteger, CustomHudStyle) {
    
    gray_background_style = 0,
    dim_background_style,
};

If not set, a gray background is used by default.
You can LoadingStyleManagermodify the style through the methods provided by this class, prompting the modification of the display duration of the hud.

Code example for modifying styles:

[[LoadingStyleManager sharedInstance] setHudStyle:dim_background_style];

The display duration of the prompt is 2s by default , and you can modify it according to your needs.
To modify how long the prompt is displayed:

[[LoadingStyleManager sharedInstance] setHudDelayTime:1.5]; //设置提示显示的时长

Show results:
insert image description here

3. Special instructions

  1. Prompt that the three icons used are placed in the resource directory, which are found from previous projects, only the **@2x icon, if you need to use it, please ask the designer to generate the corresponding @3x** icon.

  2. If you need to use other styles of prompts, please package them yourself according to the demo of MBProgressHUD .

  3. Demo Portal , welcome to download and use, to put forward comments.

Guess you like

Origin blog.csdn.net/u010389309/article/details/89530421