IOS 自定义导航栏背景

//- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
-(id)init
{
    self=[super init];
    if(self)
    {
        UINavigationBar *navBar=[self navigationBar];
        if([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
        {
//如果是IOS5
            [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"NavBar.png"] forBarMetrics:UIBarMetricsDefault];
        }
        else
        {
            UIImageView *imgView=(UIImageView*)[navBar viewWithTag:NAVBARIMAGETAG];
            if(imgView==nil)
            {
                imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,navBar.frame.size.width, navBar.frame.size.height)];
                [imgView setImage:[UIImage imageNamed:@"NavBar.png"]];
                [navBar insertSubview:imgView atIndex:0];
                [imgView release];
            }
        }
    }
    return self;
}

  

时间: 2024-08-05 11:18:21

IOS 自定义导航栏背景的相关文章

iOS 自定义导航栏笔记

一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC = [[TestViewController alloc] init]; UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:mainVC]; self.window.ro

IOS 自定义导航栏标题和返回按钮标题

IOS中自定义导航栏标题: UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(160, 0, 120, 50)]; titleText.backgroundColor = [UIColor clearColor]; titleText.textColor=[UIColor whiteColor]; [titleText setFont:[UIFont systemFontOfSize:17.0]]; [titleTex

ios 自定义导航栏和分割线

自定义导航栏: // CustomNaviBarView.h #import <UIKit/UIKit.h> @interface CustomNaviBarView : UIView { @private /** * 左侧按钮 */ UIButton* _leftButton; /** * 右侧按钮 */ UIButton* _rightButton; /** * 中部标签 */ UILabel* _navTitle; } @property(nonatomic,strong)UIButto

iOS 更改导航栏背景颜色

ios7以下的版本设置导航栏背景颜色可以使用 [[UINavigationBar appearance] setTintColor:[UIColor orangeColor]]; ios7以后: [[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]]; 默认带有一定透明效果,可以使用以下方法去除系统效果 [navigationController.navigationBar setTranslucent:NO];

ios 自定义导航栏,开启侧滑返回手势

自定义一个常用ListViewController .h文件 1 #import <UIKit/UIKit.h> 2 3 @interface ListViewController : UIViewController 4 5 -(void)diquButtonClick; 6 7 @end .m文件 1 // 2 // ListViewController.m 3 // OuLianWang 4 // 5 // Created by allenariel on 15/6/24. 6 // C

IOS 自定义导航栏

我们自己新建一个View,来自定义导航栏,如下代码: #import <UIKit/UIKit.h> @interface CustomNavigation : UIView typedef enum { customEventClickLBtn1 ,//点击了最左边的按钮 customEventClickRBtn1 , //最右边的按钮 customEventClickLBtn2 ,//点击了左边第二个按钮 customEventClickRBtn2 //点击了右边最靠左的按钮 }Custo

oc 自定义导航栏背景

 [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];   //@{}代表Dictionary     [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

iOS 自定义导航栏的返回按钮

UIBarButtonItem * item  =    [UIBarButtonItem appearance]; UIImage* image = [UIImage imageNamed:@"back_icon"]; [item setBackButtonBackgroundImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)] forState:UIControlS

IOS 实现自定义的导航栏背景以及自定义颜色的状态栏(支持7.0以及低版本)

为尊重文章原作者,转载务必注明原文地址:http://www.cnblogs.com/wt616/p/3784717.html 先看效果图: 在自定义导航栏背景时,可能会遇到以下一些问题: 1.当设置导航栏背景后,状态栏的颜色也会跟着一起改变掉,这可能不是你说希望看到的 2.IOS7以上的版本和低版本显示出来的导航栏高度位置有差别,这个差别就是状态栏的高度20,为了兼容低版本,必须统一 解决思路: 1.不正常的是状态栏的背景也一起变了,而状态栏的文字是可以通过其他API去设置的:如 [[UIAp