标签:style blog http io color os ar for sp
| 第三方类库 | 功能 | |
| WXmodel | 数据层类 | |
| FontLabel | 开源的Label类 | |
| RTLabel | Label类 | |
| DDmenuController | 左右滑动的框架 | |
| Customcatagory | 自定义导航栏 | |
1.分析结构

1.建一个主控制器MainController 继承自 UITabBarController。
建一些基础类 baseViewConttoller 继承自 UIViewController,和 BaseNavigationNaViewController 继承自 UINavigationController
建里用于显示的 ViewConttoller , HomeViewController MessageViewController ProfileViewController DiscoverViewController MoreViewController 这些都继承自 baseViewControler; 做以下设置 with xib


2.在MainController中,初始化 用于显示的控制器
-(void)_initViewController{
    
    //初始化 每个视图控制器
      HomeViewController *home=[[HomeViewController alloc]init];
      MessageViewController *message=[[MessageViewController alloc]init];
      ProfileViewController *profile=[[ProfileViewController alloc]init];
      DiscoverViewController *discover=[[DiscoverViewController alloc]init];
      MoreViewController *more=[[MoreViewController alloc]init];
    //创建一个可变数组存放 导航控制器
    NSMutableArray *viewControllers=[NSMutableArray arrayWithCapacity:5];
    //创建一个数字 存放视图控制器
    NSArray *views=@[home,message,profile,discover,more];
    //用for 循环 为 每一个 视图控制器创建导航控制器NavigationNaViewController
    for (UIViewController *viewController in views) {
        BaseNavigationNaViewController *nav=[[BaseNavigationNaViewController alloc]initWithRootViewController:viewController];
        //将导航控制器 存入数组
        [viewControllers addObject:nav];
    }
    
    // 指定选项卡栏导航控制器  的导航控制器
    self.viewControllers=viewControllers;
    
    
}
3.自定义 tabbar 首先 得禁用 自带的 tarbar ,[self.tabBar setHidden:YES];
-(void)_initTabBarView{
    
    _tabbarView=[[UIView alloc]initWithFrame:CGRectMake(0,ScreenHeight-49,320,49)];
    
    [_tabbarView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"tabbar_background.png"]]];
    [self.view addSubview:_tabbarView];
    
    //把背景名称存入数组
    NSArray *background=@[@"tabbar_home.png",@"tabbar_message_center.png",@"tabbar_profile.png",@"tabbar_discover.png",@"tabbar_more.png"];
    NSArray *heightbackground=@[@"tabbar_home_highlighted.png",@"tabbar_message_center_highlighted.png",@"tabbar_profile_highlighted.png",@"tabbar_discover_highlighted.png",@"tabbar_more_highlighted.png"];
    
    //用 for循环 创建 button 并设置背景
    for (int i=0; i<background.count; i++) {
        NSString *backimage=background[i];
        NSString *heightbackimage=heightbackground[i];
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake((64-30)/2+(i*64), (49-30)/2, 30, 30);
        button.tag=i;
        [button setImage:[UIImage imageNamed:backimage] forState:UIControlStateNormal ];
        [button setImage:[UIImage imageNamed:heightbackimage] forState:    UIControlStateHighlighted];
        [button addTarget:self action:@selector(selectedTab:) forControlEvents:UIControlEventTouchUpInside ];
        [_tabbarView addSubview:button ];
        
    }
    
    
}
指定导航栏背景色,5.0 以上用此方法
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImage *image=[UIImage imageNamed:@"navigationbar_background.png"];
    float verson=WXHLOSVersion();
    if (verson>=5.0) {
        [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault ];
    }
    // Do any additional setup after loading the view.
}
5.0以下 用这个
#import "CustomCatagory.h"
//5.0以下系统自定义UINavigationBar背景
@implementation UINavigationBar(setbackgroud)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed:@"navigationbar_background.png"];
    [image drawInRect:rect];
}
@end
4. 集成左右菜单 首先导入 DDmenuController
 //创建 mainctrl
_mainctrl=[[MainViewController alloc]init];
    
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //指定 RootViewController为  _mainctrl
    DDMenuController *menuctrl=[[DDMenuController alloc]initWithRootViewController:_mainctrl];
    //指定 leftViewControlle,rightViewController
    LeftViewController *leftctrl=[[LeftViewController alloc]init];
    RigheViewController *rigtctrl=[[RigheViewController alloc]init];
    
    menuctrl.leftViewController=leftctrl;
    menuctrl.rightViewController=rigtctrl;
    // Override point for customization after application launch.
   // self.viewController = [[[sendViewController alloc] init] autorelease];
    
    self.window.rootViewController = menuctrl;
   
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
标签:style blog http io color os ar for sp
原文地址:http://www.cnblogs.com/shuozi-love/p/4064834.html