ios nav自定义button

 

 

 

 

 

+(void)initialize{
    
    UINavigationBar *item = [UINavigationBar appearance];
    
    // 按钮的颜色
    item.tintColor = [UIColor redColor];
    // 整个背景的颜色
    item.barTintColor = [UIColor orangeColor];

}

 

    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSForegroundColorAttributeName] = [UIColor whiteColor];
    
    UINavigationBar *item = [UINavigationBar appearance];
    [item setTitleTextAttributes:dic];
    
    [item setBackgroundImage:[UIImage imageNamed:@"top"] forBarMetrics:UIBarMetricsDefault];

 

 

 

 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"back_hover"] forState:UIControlStateSelected];
        
        [btn setTitle:@"返回" forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn.size = CGSizeMake(50, 29);
//        btn.backgroundColor = [UIColor lightGrayColor];
        
//        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        btn.contentEdgeInsets = UIEdgeInsetsMake(0, -50, 0, 0);
        
        [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];

 

posted @ 2016-03-10 19:33  人生路1/5  阅读(487)  评论(0编辑  收藏  举报