IOS开发基础之微博项目第1天-OC版

纯代码创建的项目,具有参考价值
该资料来自2014年7月3号,虽然时间过去较长,但是oc和swift不同,oc语法迭代更新慢
具有一定的参考意义
涉及xib加载,纯代码创建页面,导航控制器,类分类,PCH,宏定义,封装,UITableView的使用,代理,源码在我的主页下,名称是 04-WeiBo-OneDay-OC_Version.zip
核心源码

//
//  AppDelegate.m
//  01-WeiBo-CreateFramework
//
//  Created by 鲁军 on 2021/4/18.
//
#import "AppDelegate.h"
#import "HMTabBarViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc] init];self.window.frame = [UIScreen mainScreen].bounds;self.window.rootViewController = [[HMTabBarViewController alloc] init];[self.window makeKeyAndVisible];return YES;
}
@end

PCH文件

#define HMRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]#define IOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)#import "UIView+Extension.h"
#import "UIBarButtonItem+Extension.h"#ifdef DEBUG //调试状态。打开LOG功能
#define HMLog(...) NSLog(__VA_ARGS__)
#else//发布状态关闭LOG功能
#define HMLog(...)
#endif
//
//  HMNavigationController.m
//  01-WeiBo-CreateFramework
//
//  Created by 鲁军 on 2021/4/18.
#import "HMNavigationController.h"
@interface HMNavigationController ()
@end
@implementation HMNavigationController
- (void)viewDidLoad {[super viewDidLoad];
}
+(void)initialize{UIBarButtonItem *appearance = [UIBarButtonItem appearance];NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];textAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];textAttr[NSFontAttributeName] = [UIFont systemFontOfSize:15];[appearance setTitleTextAttributes:textAttr forState:UIControlStateNormal];NSMutableDictionary *textHighAttr = [NSMutableDictionary dictionary];textHighAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];textHighAttr[NSFontAttributeName] = [UIFont systemFontOfSize:15];[appearance setTitleTextAttributes:textHighAttr forState:UIControlStateHighlighted];NSMutableDictionary *textDisableAttr = [NSMutableDictionary dictionary];textDisableAttr[NSForegroundColorAttributeName] = [UIColor lightGrayColor];textDisableAttr[NSFontAttributeName] = [UIFont systemFontOfSize:15];[appearance setTitleTextAttributes:textDisableAttr forState:UIControlStateDisabled];}- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{//    NSLog(@"pushViewController===%@",viewController);//如果现在push的不是栈底控制器 (最先push进来的那个控制器)if(self.viewControllers.count>0){viewController.hidesBottomBarWhenPushed = YES;viewController.navigationItem.leftBarButtonItem =[UIBarButtonItem itemWithImageName:@"navigationbar_back" highImageName:@"navigationbar_back_highlighted" target:self action:@selector(back)];viewController.navigationItem.rightBarButtonItem =[UIBarButtonItem itemWithImageName:@"navigationbar_more" highImageName:@"navigationbar_more_highlighted" target:self  action:@selector(more)];}[super pushViewController:viewController animated:animated];
}
-(void)back{[self popViewControllerAnimated:YES];
}
-(void)more{[self popToRootViewControllerAnimated:YES];
}
@end
//
//  HMTabBarViewController.m
//  01-WeiBo-CreateFramework
//
//  Created by 鲁军 on 2021/4/18.
//#import "HMTabBarViewController.h"
#import "HMHomeViewController.h"
#import "HMMessageViewController.h"
#import "HMDiscoverViewController.h"
#import "HMProfileViewController.h"
#import "HMNavigationController.h"@interface HMTabBarViewController ()@end@implementation HMTabBarViewController- (void)viewDidLoad {[super viewDidLoad];//添加子控制器、HMHomeViewController *home = [[HMHomeViewController alloc] init];[self addOneChildVc:home title:@"首页" imageName:@"tabbar_home" selectedImage:@"tabbar_home_selected"];/* UIImage *selectedImage = [UIImage imageNamed:@"tabbar_home_selected"];selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];home.tabBarItem.selectedImage =selectedImage;*/HMMessageViewController *message = [[HMMessageViewController alloc] init];[self addOneChildVc:message title:@"消息" imageName:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected"];HMDiscoverViewController *discover = [[HMDiscoverViewController alloc] init];[self addOneChildVc:discover title:@"发现" imageName:@"tabbar_discover" selectedImage:@"tabbar_discover_selected"];HMProfileViewController *me = [[HMProfileViewController alloc] init];[self addOneChildVc:me title:@"我" imageName:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];
}
-(void)addOneChildVc:(UIViewController *)childVc title:(NSString *) title imageName:(NSString*)imageName selectedImage:(NSString *)selectedImage
{// childVc.view.backgroundColor = HMRandomColor;/*childVc.tabBarItem.title = title;childVc.navigationItem.title = title;*/childVc.title = title;//title代替上面两行代码// 设置tabBarItem的普通文字颜色NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];textAttrs[NSForegroundColorAttributeName] =[UIColor blackColor];[childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];// 设置tabBarItem的选中文字颜色NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];selectedTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];[childVc.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];childVc.tabBarItem.image = [UIImage imageNamed:imageName];childVc.tabBarItem.selectedImage =[UIImage imageNamed:selectedImage];HMNavigationController *nav = [[HMNavigationController alloc] initWithRootViewController:childVc];[self addChildViewController:nav];
}
@end
//
//  HMHomeViewController.m
//  01-WeiBo-CreateFramework
//
//  Created by 鲁军 on 2021/4/18.
//#import "HMHomeViewController.h"
#import "HMOneViewController.h"
@interface HMHomeViewController ()
@end
@implementation HMHomeViewController- (void)viewDidLoad {[super viewDidLoad];//设置导航栏按钮//设置左边按钮self.navigationItem.leftBarButtonItem =[UIBarButtonItem itemWithImageName:@"navigationbar_friendsearch" highImageName:@"navigationbar_friendsearch_highlighted" target:self action:@selector(friendSearch)];//设置右边按钮self.navigationItem.rightBarButtonItem =[UIBarButtonItem itemWithImageName:@"navigationbar_pop" highImageName:@"navigationbar_pop_highlighted" target:self  action:@selector(pop)];/*UITextField *textFile = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 30)];textFile.backgroundColor = [UIColor grayColor];textFile.inputAccessoryView = [[[NSBundle mainBundle] loadNibNamed:@"KeyboardTool" owner:nil options:nil] lastObject];[self.view addSubview:textFile];*/
}
-(void)friendSearch{HMLog(@"222");HMOneViewController *oneVc = [[HMOneViewController alloc] init];oneVc.title = @"oneVc";[self.navigationController pushViewController:oneVc animated:YES];}
#pragma mark - Table view data source
-(void)pop{HMLog(@"1111");
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *ID =@"cell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];if(!cell){cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];}cell.textLabel.text =[ NSString stringWithFormat:@"测试---%ld",indexPath.row];return cell;
}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{UIViewController *newVc = [[UIViewController alloc] init];newVc.view.backgroundColor = [UIColor redColor];newVc.title = @"新控制器";[self.navigationController pushViewController:newVc animated:YES];
}
@end

IOS开发基础之微博项目第1天-OC版相关推荐

  1. IOS开发基础之微博项目

    IOS开发基础之微博项目 关键性代码 // // NJViewController.m // 06-预习-微博(通过代码自定义cell)// #import "NJViewControlle ...

  2. iOS开发-图片离线鉴黄 基于TensorFlow nsfw oc版

    iOS开发-图片离线鉴黄 基于TensorFlow nsfw oc版 前言-基于TensorFlow鉴黄 效果 首先要引入Firebase 鉴黄类的封装 OC版本的鉴黄demo Swift版本的鉴黄 ...

  3. IOS开发基础之模拟科技头条项目案例32

    IOS开发基础之模拟科技头条项目案例32 说说这个项目的技术要点核心 ,首先是异步网络请求,block的回调,sdWebImage的使用.各个控件的使用,NSDate日期的转换.自动适配屏幕工作,模型 ...

  4. IOS开发基础之手势解锁项目案例

    IOS开发基础之手势解锁项目案例 项目最终实现效果. 由于缺少红色的error背景图.我自己从安卓项目找到一个手势解锁,然后通过ps添加粉红色的红圈,才得以解决.为了分享给大家源码,github和本地 ...

  5. IOS开发基础之汽车品牌项目-14

    IOS开发基础之汽车品牌项目-14 // // ViewController.m // 16-汽车品牌展示02 // // Created by 鲁军 on 2021/2/3. //#import & ...

  6. IOS开发基础之UI的喜马拉雅的项目-10

    IOS开发基础之UI的喜马拉雅的项目-10 // // ViewController.m // 10-喜马拉雅 // // Created by 鲁军 on 2021/2/2. //#import & ...

  7. iOS开发基础知识--碎片44

    iOS开发基础知识--碎片44  iOS开发基础知识--碎片44 1:App跳转至系统Settings 跳转在IOS8以上跟以下是有区别的,如果是IOS8以上可以如下设置: NSURL *url = ...

  8. IOS开发基础之OC的Block入门_Day09-Block

    IOS开发基础之OC的Block入门_Day09-Block block是oc的重要的基础知识,重点之重.跟协议一样重要,是进行函数回调重要手段.在后续的UI学习具有举足轻重的地位.学会基础的bloc ...

  9. IOS开发基础之音频工具类封装AVAudioPlayer

    IOS开发基础之音频工具类封装AVAudioPlayer 源码在我的主页下面 ,项目名称是AVAudioPlayer 关键性代码 工具类的封装 // // LJAudioTool.h // AVAud ...

最新文章

  1. poj 1141(区间dp+打印路径)
  2. filezilla 定时上传_FileZilla Server安装教程 - FtpCopy数据自动备份软件(FTP定时备份)|FTP自动下载|FTP自动上传|FTP自动备份...
  3. java判断读到末尾_Flink实战:自定义KafkaDeserializationSchema(Java/Scala)
  4. 原子设计_您需要了解的有关原子设计的4件事
  5. leetcode面试题 16.19. 水域大小(深度优先搜索)
  6. 后疫情时代,银行从数字化转型到智能化“迁徙”
  7. xposed hook 静态函数_浅谈 Xposed 新概念【模块作用域】
  8. python深入和扩展_用Python来扩展Postgresql(一)
  9. 各种移动GPU压缩纹理的使用方法
  10. python爬虫爬取页面源码在本页面展示
  11. Java集合Set、Map、HashSet、HashMap、TreeSet、TreeMap等
  12. [bug]使用SharpZipLib遇到中文名称乱码问题
  13. Java笔记(day12)
  14. 【Java】Java_18 方法
  15. 3D视觉点云数据处理十大方法
  16. 华硕笔记本禁用触控板方法
  17. 5G关键技术之D2D通信技术
  18. 接近开关NPN和PNP区别
  19. Alink漫谈(二十二) :源码分析之聚类评估
  20. 【C/C++练习题】斐波那契数列

热门文章

  1. vivado链接不上开发板最有可能原因
  2. nc 模拟服务器_NC集群服务器使用详解
  3. matlab如何创建callback函数_如何学好MATLAB GUI
  4. linux小菜鸟入门,《Linux菜鸟入门》初识linux基础(示例代码)
  5. 国家电网是“围城”?辞职吗?
  6. 再刷世界纪录!3051架无人机「同时飞行」演绎震撼灯光秀
  7. 摆摊吗?我卖锅,你修手机。
  8. 下一个嵌入式大神,就是你。
  9. python输入法引擎_Bigram-MLE语言模型和模拟输入法的python实现
  10. oracle11g nid,Oracle工具之nid命令的使用