//
//  XVBaseViewController.m
//  fastservice
//
//  Created by xuning on 2/2/24.
//

#import "XVBaseViewController.h"

@interface XVBaseViewController ()


@end

@implementation XVBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.view.backgroundColor = DEFAULT_BACKGROUND_COLOR;
    
    [self setNavigationBarsetBackgroundColor:[UIColor whiteColor]];
    

    
}

- (void)back {
    // 判断两种情况: push 和 present
    if ((self.presentedViewController || self.presentingViewController) && self.childViewControllers.count == 1) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}


- (void)setNavigationBarsetBackgroundColor:(UIColor *)color {
    
    if(@available(iOS 15.0, *)) {
        
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        
        appearance.backgroundImage = [UIImage imageWithColor:color];// 图片
        
        appearance.backgroundColor = color;// 背景色
        
        appearance.shadowColor = UIColor.clearColor; // 阴影
        
        self.navigationController.navigationBar.standardAppearance = appearance;
        
        self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
        
    }else{
        
        // Fallback on earlier versions
        self.navigationController.navigationBar.translucent = NO;
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:color] forBarMetrics:UIBarMetricsDefault];
        
        [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:color]];
        
    }
}
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed:@"nodata_图标"];
}


- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSMutableAttributedString *text = [NSMutableAttributedString new];
    UIFont *font = [UIFont systemFontOfSize:15];
    
    [text appendAttributedString:[[NSAttributedString alloc] initWithString:@"暂无数据" attributes:@{NSFontAttributeName : font,NSForegroundColorAttributeName:kHexRGB(0xB49A9A)}]];
    return text;
    
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}


@end
