仿新浪微博IOS客户端(v5.2.8)

转载请标明出处:

声明:仿新浪微博项目,所用所有图片资源都来源于官方新浪微博IOS客户端,编写本应用的目的在于学习交流,如涉及侵权请告知,我会及时换掉用到的相关图片。

一、在Xcode6下添加.pch文件 对于使用惯了之前版本Xcode的朋友来说,在系统提醒之下升级到Xcode 6之后,发现新建项目后Xcode不再帮我们创建.pch文件了。可是我们已经习惯了,把一些在很多地方都用的宏写到.pch文件中,那么没有这个文件该如何添加一个呢?下面先给我们的仿新浪微博项目添加一个.pch文件,具体步骤如下:1、选中Supporting Files右键New File…,如下图

2、接下来选择创建一个PCH文件,如下图:

3、选择Next、Create就创建完毕了。接下来修改配置文件,在搜索框中输入“Prefix Header”,在Prefix Header这一项,填写上一步创建的pch文件的相对路径,修改完后如下图:

二、在上一篇的基础上,设置导航栏外观,具体实现如下:

1、创建WBNavigationController类,让其继承自UINavigationController。用我们自定义的WBNavigationController替换掉上一讲中使用UINavigationController类的地方,具体代码如下:

// 使用系统默认的UINavigationController//[self addChildViewController:[[UINavigationController alloc] initWithRootViewController:childViewController]];// 使用我们自定义的导航栏(WBNavigationController继承自UINavigationController)WBNavigationController * navigationController = [[WBNavigationController alloc]initWithRootViewController:childViewController];[self addChildViewController:navigationController];2、在WBNavigationController.m文件中添加,设置整个项目中所有UIBarButtonItem的外观样式,,具体代码如下:#pragma mark 在运行时仅被触发一次#pragma mark 值得注意的是在此之前,父类的方法已经被执行过一次了,所以不需要调用super的该函数。+ (void)initialize{// 设置整个项目中所有UIBarButtonItem的外观样式UIBarButtonItem *item = [UIBarButtonItem appearance];// 设置在UIControlStateNormal下,导航栏文字的大小和颜色[item setTitleTextAttributes:@{NSForegroundColorAttributeName:kColor(64, 64, 64),NSFontAttributeName:[UIFont systemFontOfSize:15]}forState:UIControlStateNormal];// 设置在UIControlStateHighlighted下,导航栏文字的大小和颜色[item setTitleTextAttributes:@{NSForegroundColorAttributeName:kColor(253, 109, 10),NSFontAttributeName:[UIFont systemFontOfSize:15]}forState:UIControlStateHighlighted];}3、拦截所有push进来的控制器,设置除根控制器外的控制器的导航栏外观,具体实现如下:#pragma mark 重写这个方法目的:能够拦截所有push进来的控制器#pragma mark viewController这个参数是即将push进来的控制器- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{if (self.viewControllers.count > 0) {// 如果push进来的控制器viewController,不是根控制器// 自动显示和隐藏tabbarviewController.hidesBottomBarWhenPushed = YES;// 设置导航栏上左边的返回按钮viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back)image:@"navigationbar_back_withtext"highImage:@"navigationbar_back_withtext_highlighted"title:self.title];}[super pushViewController:viewController animated:animated];}- (void)back{[self popViewControllerAnimated:YES];}4、设置首页导航栏上的按钮,具体实现如下://// HomeViewController.m// SinaWeibo//// Created by android_ls on 15/5/17.// Copyright (c) 2015年 android_ls. All rights reserved.//// 首页动态列表控制器#import "HomeViewController.h"#import "UIBarButtonItem+Category.h"#import "FriendAttentionStatusViewController.h"@interface HomeViewController ()@end@implementation HomeViewController- (void)viewDidLoad {[super viewDidLoad];// 设置导航栏左侧的按钮self.navigationItem.leftBarButtonItem = [UIBarButtonItem leftBarButtonItemWithTarget:selfaction:@selector(friendsearch)image:@"navigationbar_friendsearch"highImage:@"navigationbar_friendsearch_highlighted"];// 设置导航栏右侧的弹出下拉菜单按钮self.navigationItem.rightBarButtonItem = [UIBarButtonItem rightBarButtonItemWithTarget:selfaction:@selector(pop)image:@"navigationbar_pop"highImage:@"navigationbar_pop_highlighted"];}#pragma mark 打开好友关注动态控制器-(void)friendsearch{MyLog(@"用户点击了左侧按钮");FriendAttentionStatusViewController *friendAttentionStatusVC = [[FriendAttentionStatusViewController alloc]init];[self.navigationController pushViewController:friendAttentionStatusVC animated:YES];}#pragma mark 弹出下拉菜单-(void)pop{MyLog(@"用户点击了右侧弹出下拉菜单按钮");}@end

5、已实现的效果图如下:

每年的情人节圣诞节除夕,也和他共度。甚至连吵架也是重复的,

仿新浪微博IOS客户端(v5.2.8)

相关文章:

你感兴趣的文章:

标签云: