199 lines
5.7 KiB
Objective-C
199 lines
5.7 KiB
Objective-C
//
|
|
// BaseViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by zu on 2021/8/31.
|
|
//
|
|
|
|
#import "BaseViewController.h"
|
|
///Tool
|
|
#import "XCHUDTool.h"
|
|
#import "ThemeColor.h"
|
|
|
|
@interface BaseViewController ()
|
|
|
|
@end
|
|
|
|
@implementation BaseViewController
|
|
|
|
- (void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
if (@available(iOS 13.0, *)) {
|
|
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
|
|
} else {
|
|
// Fallback on earlier versions
|
|
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
|
|
}
|
|
// 根据子类属性重写判断是否隐藏导航栏
|
|
[self.navigationController setNavigationBarHidden:self.isHiddenNavBar animated:animated];
|
|
///解决iOS15 导航栏下面有一条黑色的线 @fengshuo
|
|
if (@available(iOS 15.0, *)) {
|
|
[self.navigationController.navigationBar.subviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
|
|
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0) {
|
|
//iOS10,改变了导航栏的私有接口为_UIBarBackground
|
|
if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
|
|
[view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if ([obj isKindOfClass:NSClassFromString(@"_UIBarBackgroundShadowView")]) {
|
|
obj.hidden = YES;
|
|
}
|
|
}];
|
|
}
|
|
}
|
|
}];
|
|
}
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self themeConfig];
|
|
}
|
|
|
|
- (void)themeConfig {
|
|
self.view.backgroundColor = [ThemeColor appBackgroundColor];
|
|
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
|
|
}
|
|
|
|
/**
|
|
隐藏导航条
|
|
*/
|
|
- (void)hideNavigationBar {
|
|
[self.navigationController setNavigationBarHidden:YES animated:YES];
|
|
}
|
|
|
|
|
|
/**
|
|
显示导航条
|
|
*/
|
|
- (void)showNavigationBar {
|
|
[self.navigationController setNavigationBarHidden:NO];
|
|
}
|
|
|
|
/**
|
|
显示状态栏
|
|
*/
|
|
- (void)showStatusBar {
|
|
[UIApplication sharedApplication].statusBarHidden = NO;
|
|
}
|
|
|
|
/**
|
|
隐藏状态栏
|
|
*/
|
|
- (void)hideStatusBar {
|
|
[UIApplication sharedApplication].statusBarHidden = YES;
|
|
}
|
|
|
|
- (void)showSuccessToast:(NSString *)msg {
|
|
[XCHUDTool showSuccessWithMessage:msg];
|
|
}
|
|
|
|
- (void)showErrorToast:(NSString *)msg {
|
|
[XCHUDTool showErrorWithMessage:msg];
|
|
}
|
|
|
|
- (void)showLoading {
|
|
[XCHUDTool showLoading];
|
|
}
|
|
|
|
- (void)hideHUD {
|
|
[XCHUDTool hideHUD];
|
|
}
|
|
|
|
/**
|
|
显示加载个播房loading
|
|
*/
|
|
- (void)showAnchorLoading {
|
|
[XCHUDTool showAnchorLoading];
|
|
}
|
|
#pragma mark - 导航栏添加操作按钮
|
|
|
|
/// 添加图片
|
|
/// @param imageNames 图片的数组
|
|
/// @param isLeft 是否在左边
|
|
/// @param target 接受事件的
|
|
/// @param action 点击
|
|
/// @param tags tag
|
|
- (void)addNavigationItemWithImageNames:(NSArray *)imageNames isLeft:(BOOL)isLeft target:(id)target action:(SEL)action tags:(NSArray * _Nullable)tags {
|
|
NSMutableArray * items = [[NSMutableArray alloc] init];
|
|
NSInteger i = 0;
|
|
for (NSString * imageName in imageNames) {
|
|
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
|
|
btn.frame = CGRectMake(0, 0, 30, 30);
|
|
if(isLeft){
|
|
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
|
|
}else{
|
|
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
|
|
}
|
|
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
|
|
btn.tag = [tags[i++] integerValue];
|
|
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:btn];
|
|
[items addObject:item];
|
|
}
|
|
if (isLeft) {
|
|
self.navigationItem.leftBarButtonItems = items;
|
|
} else {
|
|
self.navigationItem.rightBarButtonItems = items;
|
|
}
|
|
}
|
|
|
|
/// 添加文字 不可点击的时候颜色
|
|
/// @param titles 文字的数组
|
|
/// @param titleColor 文字的颜色
|
|
/// @param isLeft 是否在左边
|
|
/// @param target 目标
|
|
/// @param action 点击
|
|
/// @param tags tag
|
|
- (void)addNavigationItemWithTitles:(NSArray *)titles titleColor:(UIColor *)titleColor isLeft:(BOOL)isLeft target:(id)target action:(SEL)action tags:(NSArray * _Nullable)tags {
|
|
NSMutableArray * items = [[NSMutableArray alloc] init];
|
|
//调整按钮位置
|
|
UIBarButtonItem* spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
//将宽度设为负值
|
|
spaceItem.width= -10;
|
|
[items addObject:spaceItem];
|
|
if (titleColor == nil) {
|
|
titleColor = [ThemeColor mainTextColor];
|
|
}
|
|
NSInteger i = 0;
|
|
for (NSString * title in titles) {
|
|
UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
btn.frame = CGRectMake(0, 0, 30, 20);
|
|
[btn setTitle:title forState:UIControlStateNormal];
|
|
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
|
|
btn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
[btn setTitleColor:titleColor forState:UIControlStateNormal];
|
|
btn.tag = [tags[i++] integerValue];
|
|
[btn sizeToFit];
|
|
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:btn];
|
|
[items addObject:item];
|
|
}
|
|
if (isLeft) {
|
|
self.navigationItem.leftBarButtonItems = items;
|
|
} else {
|
|
self.navigationItem.rightBarButtonItems = items;
|
|
}
|
|
}
|
|
|
|
|
|
/// 自定义的View
|
|
/// @param isLeft 是否在左边
|
|
- (void)addNavigationItemWithItems:(NSArray<UIView *> *)views
|
|
isLeft:(BOOL)isLeft {
|
|
NSMutableArray * items = [[NSMutableArray alloc] init];
|
|
//调整按钮位置
|
|
UIBarButtonItem* spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
//将宽度设为负值
|
|
spaceItem.width= -10;
|
|
[items addObject:spaceItem];
|
|
for (UIView * view in views) {
|
|
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:view];
|
|
[items addObject:item];
|
|
}
|
|
if (isLeft) {
|
|
self.navigationItem.leftBarButtonItems = items;
|
|
} else {
|
|
self.navigationItem.rightBarButtonItems = items;
|
|
}
|
|
}
|
|
|
|
|
|
@end
|