美文网首页
IOS15.0之百思不得其姐项目搭建

IOS15.0之百思不得其姐项目搭建

作者: Johnson_9d92 | 来源:发表于2021-09-26 18:52 被阅读0次
Xnip2021-09-26_18-43-16.jpg

其主要代码是

//
//  AppDelegate.m
//  BuDeJie
//
//  Created by lujun on 2021/9/26.
//

#import "AppDelegate.h"
#import "HMTabBarController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window1 = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
    HMTabBarController *tabVc = [[HMTabBarController alloc] init];
    self.window1.rootViewController = tabVc;
    self.window1.backgroundColor = [UIColor whiteColor];
    [self.window1 makeKeyAndVisible];
    return YES;
}
@end
//
//  HMTabBarController.m
//  BuDeJie
//
//  Created by lujun on 2021/9/26.
//

#import "HMTabBarController.h"

#import "HMNewViewController.h"
#import "HMEssenceViewController.h"
#import "HMPublishViewController.h"
#import "HMFriendTrendViewController.h"
#import "HMMeViewController.h"
#import "UIImage+image.h"

@interface HMTabBarController ()
@end
@implementation HMTabBarController
//只会调用一次
+ (void)load{
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *dicts = [NSMutableDictionary dictionary];
    dicts[NSForegroundColorAttributeName] = [UIColor systemPinkColor];
    [item setTitleTextAttributes:dicts forState:UIControlStateSelected];
    //设置字体,只有设置正常状态下,才会生效
    NSMutableDictionary *dictsNor = [NSMutableDictionary dictionary];
    dictsNor[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:dictsNor forState:UIControlStateNormal];
    
}
//注意可能调用多次
//+ (void)initialize{
//    if(self == [HMTabBarController class]) {
//
//    {
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupAllChildViewController];
    [self setupAllTitleButton];
}

-(void)setupAllChildViewController{
    HMEssenceViewController *essenceVc = [[HMEssenceViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:essenceVc];
    [self addChildViewController:nav];
    //新帖
    HMNewViewController *newVc = [[HMNewViewController alloc] init];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:newVc];
    [self addChildViewController:nav1];
    //发布
    HMPublishViewController *publishVc = [[HMPublishViewController alloc] init];
    [self addChildViewController:publishVc];
    //关注
    HMFriendTrendViewController *ftVc = [[HMFriendTrendViewController alloc] init];
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:ftVc];
    [self addChildViewController:nav3];
    //我
    HMMeViewController *meVc = [[HMMeViewController alloc] init];
    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:meVc];
    [self addChildViewController:nav4];
}

-(void)setupAllTitleButton{
    UINavigationController *nav=self.childViewControllers[0];
    nav.tabBarItem.title = @"精华";
    nav.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    nav.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_essence_click_icon"];;
    UINavigationController *nav1=self.childViewControllers[1];
    nav1.tabBarItem.title = @"新帖";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_new_click_icon"];
    HMPublishViewController *publishVc=self.childViewControllers[2];
    publishVc.tabBarItem.title = @"发布";
    publishVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon"];
    publishVc.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_publish_click_icon"];
    UINavigationController *nav3=self.childViewControllers[3];
    nav3.tabBarItem.title = @"关注";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    nav3.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_friendTrends_click_icon"];
    UINavigationController *nav4=self.childViewControllers[4];
    nav4.tabBarItem.title = @"我";
    nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    nav4.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_me_click_icon"];
}

@end

分类

//
//  UIImage+image.h
//  BuDeJie
//
//  Created by lujun on 2021/9/26.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UIImage (image)
+(UIImage *)imageOriginalWithName:(NSString *)imageName;
@end

NS_ASSUME_NONNULL_END

//
//  UIImage+image.m
//  BuDeJie
//
//  Created by lujun on 2021/9/26.
//

#import "UIImage+image.h"

@implementation UIImage (image)

+(UIImage *)imageOriginalWithName:(NSString *)imageName{
    UIImage *img = [UIImage imageNamed:imageName];
    
    return [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
@end

所有第一天的全部代码在这儿。https://e.coding.net/lujun1/baisibudeqijie/BuDeJie_1.git

相关文章

网友评论

      本文标题:IOS15.0之百思不得其姐项目搭建

      本文链接:https://www.haomeiwen.com/subject/nxfcnltx.html