142 lines
5.4 KiB
Objective-C
Executable File

//
// FirstViewController.m
// Talk
//
// Created by xuzs on 22/10/11.
// Copyright (c) 2022年 xuzs. All rights reserved.
//
#import "BaseViewController.h"
#import "HKHTextField.h"
//#import "MainTabBar.h"
#import "UIView+AutoLayout.h"
#import "UI.h"
#import "Pub.h"
@interface BaseViewController ()
@end
@implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
//https://juejin.cn/post/7049648953255526430
if ([[UIDevice currentDevice].systemVersion floatValue] >= 15.0) {
UINavigationBarAppearance *apearance = [[UINavigationBarAppearance alloc] init];
//apearance.configureWithOpaqueBackground;
apearance.backgroundEffect = nil;
apearance.backgroundImage = [UI imageWithColor:[UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1] size:CGSizeMake(1.0, 1.0)];
apearance.shadowColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];
apearance.backgroundColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];
self.navigationController.navigationBar.standardAppearance = apearance;
self.navigationController.navigationBar.scrollEdgeAppearance = apearance;
}
[UI SetRView:self.view Top:0 Right:0 Bottom:0 Left:0];
self.view.backgroundColor= [UI colorWithHex:0xffffff];
int w = [UI getScreenWidth];
int navh = [UI getNavHeight];
// Do any additional setup after loading the view, typically from a nib.
self.navMidLabel = [UI NewLabel:@"" Color:[UIColor whiteColor] Size:18. Align:NSTextAlignmentCenter];
self.navMidLabel.frame = CGRectMake(navh, 0, w-2*navh, navh);
self.navigationItem.titleView = self.navMidLabel;
if (self.navigationController.viewControllers.count>1) {
[self setNavBack];
}
}
- (void)setNavTitle:(NSString *)title{
self.navMidLabel.text = title;
}
- (void)setNavBack{
if(!self.navLeftImg){
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:@"back"] toSize:CGSizeMake(20, 20)];
}
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:@selector(pageBack)];
[item setTintColor:[UIColor whiteColor]];
self.navigationItem.leftBarButtonItem = item;
}
- (void)setNavLeft:(NSString *)imgname action:(SEL)action{
if(!self.navLeftImg){
self.navLeftImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
}
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navLeftImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
[item setTintColor:[UIColor whiteColor]];
self.navigationItem.leftBarButtonItem = item;
}
- (void)setNavRight:(NSString *)imgname action:(SEL)action{
if(!self.navRightImg){
self.navRightImg = [UI reSizeImage: [UIImage imageNamed:imgname] toSize:CGSizeMake(20, 20)];
}
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:self.navRightImg style:UIBarButtonItemStyleDone target:self action:(SEL)action];
[item setTintColor:[UIColor whiteColor]];
self.navigationItem.rightBarButtonItem = item;
}
- (void)pageBack{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)toastLabel:(NSString *)msg{
}
- (void)alert:(NSString *)msg{
if([Pub getApp].activeTextField){[[Pub getApp].activeTextField resignFirstResponder];}
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.toastLabel) {
self.toastLabel = [[UILabel alloc] init];
self.toastLabel.backgroundColor = [UIColor colorWithRed:0. green:0. blue:0. alpha:0.5];
//_titleLabel.numberOfLines = 0;
self.toastLabel.font = [UIFont systemFontOfSize:12.0f];
self.toastLabel.textColor = [UIColor whiteColor];
self.toastLabel.textAlignment = NSTextAlignmentCenter;
self.toastLabel.text = NSLocalizedString(@"", nil);
[self.toastLabel.layer setMasksToBounds:YES];
[self.toastLabel.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
//[self.toastLabel.layer setBorderWidth:1.0];
//self.toastLabel.layer.borderColor=[UIColor grayColor].CGColor;
//self.toastLabel.hidden = true;
self.toastLabel.layer.opacity = 1.;
}
[self.view addSubview:self.toastLabel];
[UI setFrameInView:self.toastLabel Width:@"50%" Height:@"30" TranslateX:0 TranslateY:@"10vh" InView:nil Position:UIBottomMid];
self.toastLabel.text = NSLocalizedString(msg, nil);
self.toastLabel.layer.opacity = 1.;
if(self.timer_hide_toast){
[self.timer_hide_toast invalidate];
self.timer_hide_toast = nil;
}
self.timer_hide_toast = [NSTimer scheduledTimerWithTimeInterval:1.5
target:self selector:@selector(alert_cancel)
userInfo:nil repeats:YES];
});
}
- (void)alert_cancel{
[self.timer_hide_toast invalidate];
self.timer_hide_toast = nil;
self.toastLabel.text = NSLocalizedString(@"", nil);
// CATransition *anim = [CATransition animation];
// anim.duration = 1;
// anim.type = kCATransitionFade;
// [self.toastLabel.layer addAnimation:anim forKey:nil];
[UIView animateWithDuration:.3 animations: ^{
self.toastLabel.layer.opacity = 0.;
}];
}
@end