IOS第一天-新浪微博 - 框架的搭建

*************HWAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // 1.创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;

    // 2.设置根控制器
    self.window.rootViewController = [[HWTabBarViewController alloc] init];

    // 4.显示窗口
    [self.window makeKeyAndVisible];
    return YES;
}
*******HWTabBarViewController.m
#import "HWTabBarViewController.h"
#import "HWHomeViewController.h"
#import "HWMessageCenterViewController.h"
#import "HWDiscoverViewController.h"
#import "HWProfileViewController.h"
#import "HWNavigationController.h"

@interface HWTabBarViewController ()

@end

@implementation HWTabBarViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // 1.初始化子控制器
    HWHomeViewController *home = [[HWHomeViewController alloc] init];
    [self addChildVc:home title:@"首页" image:@"tabbar_home" selectedImage:@"tabbar_home_selected"];

    HWMessageCenterViewController *messageCenter = [[HWMessageCenterViewController alloc] init];
    [self addChildVc:messageCenter title:@"消息" image:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected"];

    HWDiscoverViewController *discover = [[HWDiscoverViewController alloc] init];
    [self addChildVc:discover title:@"发现" image:@"tabbar_discover" selectedImage:@"tabbar_discover_selected"];

    HWProfileViewController *profile = [[HWProfileViewController alloc] init];
    [self addChildVc:profile title:@"我" image:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];
}

/**
 *  添加一个子控制器
 *
 *  @param childVc       子控制器
 *  @param title         标题
 *  @param image         图片
 *  @param selectedImage 选中的图片
 */
- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置子控制器的文字
    childVc.title = title; // 同时设置tabbar和navigationBar的文字
//    childVc.tabBarItem.title = title; // 设置tabbar的文字
//    childVc.navigationItem.title = title; // 设置navigationBar的文字

    // 设置子控制器的图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = HWColor(123, 123, 123);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    childVc.view.backgroundColor = HWRandomColor;   //设置了 这个会实例化 view

    // 先给外面传进来的小控制器 包装 一个导航控制器
    HWNavigationController *nav = [[HWNavigationController alloc] initWithRootViewController:childVc];
    // 添加为子控制器
    [self addChildViewController:nav];
}

@end

************HWTabBarViewController.h(导航控制器)

#import <UIKit/UIKit.h>

@interface HWTabBarViewController : UITabBarController

@end

***********HWNavigationController.m

#import "HWNavigationController.h"

@interface HWNavigationController ()

@end

@implementation HWNavigationController

+ (void)initialize
{
    // 设置整个项目所有item的主题样式
    UIBarButtonItem *item = [UIBarButtonItem appearance];

    // 设置普通状态
    // key:NS****AttributeName
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];

    // 设置不可用状态
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.7];

    //  每一个像素都有自己的颜色,每一种颜色都可以由RGB3色组成
    //  12bit颜色: #f00  #0f0 #00f #ff0
    //  24bit颜色: #ff0000 #ffff00  #000000  #ffffff

    // #ff ff ff
    // R:255
    // G:255
    // B:255

    // RGBA
    //  32bit颜色: #556677

    // #ff00ff

    disableTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 *  重写这个方法目的:能够拦截所有push进来的控制器
 *
 *  @param viewController 即将push进来的控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) { // 这时push进来的控制器viewController,不是第一个子控制器(不是根控制器)
        /* 自动显示和隐藏tabbar */
        viewController.hidesBottomBarWhenPushed = YES;

        /* 设置导航栏上面的内容 */
        // 设置左边的返回按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:@"navigationbar_back" highImage:@"navigationbar_back_highlighted"];

        // 设置右边的更多按钮
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(more) image:@"navigationbar_more" highImage:@"navigationbar_more_highlighted"];
    }

    [super pushViewController:viewController animated:animated];
}

- (void)back
{
#warning    这里要用self,不是self.navigationController
    // 因为self本来就是一个导航控制器,self.navigationController这里是nil的
    [self popViewControllerAnimated:YES];
}

- (void)more           //返回到跟控制器
{
    [self popToRootViewControllerAnimated:YES];
}
@end

************HWHomeViewController.m

#import "HWHomeViewController.h"

@interface HWHomeViewController ()

@end

@implementation HWHomeViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    /* 设置导航栏上面的内容 */
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(friendSearch) image:@"navigationbar_friendsearch" highImage:@"navigationbar_friendsearch_highlighted"];

    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(pop) image:@"navigationbar_pop" highImage:@"navigationbar_pop_highlighted"];
}

- (void)friendSearch
{
    NSLog(@"friendSearch");
}

- (void)pop
{
    NSLog(@"pop");
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

@end
HWHomeViewController.h
#import <UIKit/UIKit.h>

@interface HWHomeViewController : UITableViewController

@end

************HWMessageCenterViewController.m (消息)

#import "HWMessageCenterViewController.h"
#import "HWTest1ViewController.h"

@interface HWMessageCenterViewController ()

@end

@implementation HWMessageCenterViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // style : 这个参数是用来设置背景的,在iOS7之前效果比较明显, iOS7中没有任何效果
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"写私信" style:UIBarButtonItemStylePlain target:self action:@selector(composeMsg)];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // 这个item不能点击(目前放在viewWillAppear就能显示disable下的主题)
    self.navigationItem.rightBarButtonItem.enabled = NO;
}

- (void)composeMsg
{
    NSLog(@"composeMsg");
}

#pragma mark - Table view data sourc
- (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:@"test-message-%d", indexPath.row];

    return cell;
}

#pragma mark - 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWTest1ViewController *test1 = [[HWTest1ViewController alloc] init];
    test1.title = @"测试1控制器";
    // 当test1控制器被push的时候,test1所在的tabbarcontroller的tabbar会自动隐藏
    // 当test1控制器被pop的时候,test1所在的tabbarcontroller的tabbar会自动显示
//    test1.hidesBottomBarWhenPushed = YES;

    // self.navigationController === HWNavigationController
    [self.navigationController pushViewController:test1 animated:YES];
}
@end

************HWMessageCenterViewController.h (消息)

#import <UIKit/UIKit.h>

@interface HWMessageCenterViewController : UITableViewController

@end

**********HWDiscoverViewController.m(发现)

#import "HWDiscoverViewController.h"

@interface HWDiscoverViewController ()

@end

@implementation HWDiscoverViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

@end

**********HWDiscoverViewController.h(发现)

#import <UIKit/UIKit.h>

@interface HWDiscoverViewController : UITableViewController

@end

HWProfileViewController.m(我)

#import "HWProfileViewController.h"
#import "HWTest1ViewController.h"

@interface HWProfileViewController ()

@end

@implementation HWProfileViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"设置" style:0 target:self action:@selector(setting)];
//    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(setting) image:@"navigationbar_pop" highImage:@"navigationbar_pop_highlighted"];
}

- (void)setting
{
    HWTest1ViewController *test1 = [[HWTest1ViewController alloc] init];
    test1.title = @"test1";
    [self.navigationController pushViewController:test1 animated:YES];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

@end

***************HWProfileViewController.h(我)

#import <UIKit/UIKit.h>

@interface HWProfileViewController : UITableViewController

@end
				
时间: 2024-08-09 16:42:54

IOS第一天-新浪微博 - 框架的搭建的相关文章

iOS之UI--主流框架的搭建-- 仿制QQ的UI框架

iOS之UI--主流框架的搭建-- 仿制QQ的UI框架 使用XCode搭建多个控制器界面,一般在实际开发中建议超过四个控制器界面使用纯代码. 下面的实例其实已经超过了四个,总结详细步骤的目的,主要是更熟悉XCode的StoryBoard使用细节. 先直接上我们这个主流框架要达到的效果: 首先我们需要设置应用程序的图标: 素材百度云链接: http://pan.baidu.com/s/1dEqz7Vj 密码: g34e 然后是设定应用程序启动界面的素材百度云链接: http://pan.baidu

仿制新浪微博iOS客户端之二-项目基础搭建及相关设置

上一次的文章主要提到了仿制新浪微博所用到的一些技术和知识点,那本文就开始进入正式的项目实施阶段了.首先要做的自然是项目的创建和相关的设置,以及基础框架的搭建了. 一.项目创建及相关设置 1.项目创建 现在越来越多的的公司开始使用Swift开发iOS和AppleWatch的项目,因此此次我们的开发也使用Swift语言来进行,新建项目,设置如下: 既然是仿制,自然可以当成是一个练习,项目名称:“WeiboTest”,编程语言选择“Swift”.然后“下一步”直到创建完成. 2.应用图标设置 将应用图

&lt;转&gt;从Java转iOS第一个项目总结

从Java转iOS第一个项目总结 阅读目录 0.前言 1.项目介绍 2.项目使用的第三方开源库 3.工具和插件介绍 4.集成友盟 5.即时通讯 6.项目总结 0.前言 本人14年12月份,从网站开发组转到了移动开发组,自己的java两年半工作经验变成了object-c零经验.2015年1月份新启动了一个移动项目,年后因为人事变动,自己从辅助开发变成了"核心"开发,目前项目基本接近尾声,下面进行总结,希望对一些人能有帮助, 另外也希望ios大牛进行指导 回到顶部 1.项目介绍 项目属于一

瀑布流框架的搭建

瀑布流大家都应该熟悉了,现在大部分电商应用中或多或少的都用到瀑布流,它可以吸引用户的眼球,使用户不易产生视觉疲劳,苹果在iOS6中增添了UICollectionView控件,这个控件可以说是UITableView的升级版,通过这个控件我们就能很简单的做出瀑布流,后面通过自己的封装可以让其变成一个小框架,更简单的应用到我们之后的开发中 最近开通了简书欢迎大家关注,我会不定期的分享我的iOS开发经验  点击关注-->Melody_Zhy 如果想做瀑布流,那么就要自定义CollectionViewFl

OSGi原理与最佳实践:第一章 OSGi框架简介(5)Spring-DM

OSGi原理与最佳实践:第一章 OSGi框架简介(5)Spring-DM 由  ValRay 发布 已被浏览8409次 共有3条评论 已被2个人收藏 2013-08-16 21:29 顶(1) 踩(0) osgi原理与最佳实践 1.3 Spring-DM 1.3.1 简介 Spring-DM 指的是 Spring Dynamic Modules.Spring-DM 的主要目的是能够方便地将 Spring 框架 和OSGi框架结合在一起,使得使用Spring的应用程序可以方便简单地部署在OSGi环

iOS 开发之照片框架详解

一. 概要 在 iOS 设备中,照片和视频是相当重要的一部分.最近刚好在制作一个自定义的 iOS 图片选择器,顺便整理一下 iOS 中对照片框架的使用方法.在 iOS 8 出现之前,开发者只能使用 AssetsLibrary 框架来访问设备的照片库,这是一个有点跟不上 iOS 应用发展步伐以及代码设计原则但确实强大的框架,考虑到 iOS7 仍占有不少的渗透率,因此 AssetsLibrary 也是本文重点介绍的部分.而在 iOS8 出现之后,苹果提供了一个名为 PhotoKit 的框架,一个可以

iOS开发——实战OC篇&amp;环境搭建之Xib(玩转UINavigationController与UITabBarController)

iOS开发——实战OC篇&环境搭建之Xib(玩转UINavigationController与UITabBarController) 前面我们介绍了StoryBoard这个新技术,和纯技术编程的代码创建界面,本篇我们将介绍一个老的技术,但是在很多的公司或者库里面还是使用这个技术,既然如此它肯定有他的好处,至于好处这里我就不一一介绍了.在Xcode5之前是只能使用Xib或者代码的,而代码又对于很多初学者来说算是一个难题.毕竟不知道怎么下手.所以我就总结了一下这段时间自己编写程序的一个实例来说明怎么

iOS开发——实战OC篇&amp;环境搭建之纯代码(玩转UINavigationController与UITabBarController)

iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController) 这里我们就直接上实例: 一:新建一个项目singleView Controller,命名未iCocos 二:由于我们使用的纯代码实现的,所以删除其中的StoryBoard和Viewtroller的两个文件 三:新建一个继承自TabBar Controller的类,我们命名问iCocos ViewController 三:在Appdelegate的实现文件中导入刚刚

zf框架环境搭建

apache配置: 1.....在#LoadModule vhost_alias_module modules/mod_vhost_alias.so后面加上 LoadModule php5_module C:/php5.3/php5apache2_2.dllPHPIniDir "C:/php5.3/"AddType application/x-httpd-php .php .html .phtml php配置: 1,打开extension=php_mysql.dllextension=