IOS开发基础之微博项目第1天-OC版
生活随笔
收集整理的這篇文章主要介紹了
IOS开发基础之微博项目第1天-OC版
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
IOS開發(fā)基礎(chǔ)之微博項(xiàng)目第1天-OC版
純代碼創(chuàng)建的項(xiàng)目,具有參考價值
該資料來自2014年7月3號,雖然時間過去較長,但是oc和swift不同,oc語法迭代更新慢
具有一定的參考意義
涉及xib加載,純代碼創(chuàng)建頁面,導(dǎo)航控制器,類分類,PCH,宏定義,封裝,UITableView的使用,代理,源碼在我的主頁下,名稱是 04-WeiBo-OneDay-OC_Version.zip
核心源碼
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 //調(diào)試狀態(tài)。打開LOG功能 #define HMLog(...) NSLog(__VA_ARGS__) #else//發(fā)布狀態(tài)關(guān)閉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);//如果現(xiàn)在push的不是棧底控制器 (最先push進(jìn)來的那個控制器)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:@"發(fā)現(xiàn)" 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代替上面兩行代碼// 設(shè)置tabBarItem的普通文字顏色NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];textAttrs[NSForegroundColorAttributeName] =[UIColor blackColor];[childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];// 設(shè)置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];//設(shè)置導(dǎo)航欄按鈕//設(shè)置左邊按鈕self.navigationItem.leftBarButtonItem =[UIBarButtonItem itemWithImageName:@"navigationbar_friendsearch" highImageName:@"navigationbar_friendsearch_highlighted" target:self action:@selector(friendSearch)];//設(shè)置右邊按鈕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總結(jié)
以上是生活随笔為你收集整理的IOS开发基础之微博项目第1天-OC版的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 7款最流行的在线项目管理工具推荐
- 下一篇: OpenCL memory object