码迷,mamicode.com
首页 > 其他好文 > 详细

自定义navigationbar

时间:2015-12-09 16:45:26      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

 

   UINavigationBar *bar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, 64)];

    [bar setBackgroundImage:[UIImage imageNamed:@"blackbg"] forBarMetrics:UIBarMetricsDefault];

    UINavigationItem *item = [[UINavigationItem alloc] init];

    

    UIButton *backBarButton=[[UIButton alloc] initWithFrame:CGRectMake(0, 7, 30, 30)];

    [backBarButton setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];

    backBarButton.showsTouchWhenHighlighted=YES;

    [backBarButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];

    

    UIBarButtonItem *backItem=[[UIBarButtonItem alloc] initWithCustomView:backBarButton];

    item.leftBarButtonItem = backItem;

    [bar pushNavigationItem:item animated:NO];

    [self.view addSubview:bar];

    

    UILabel * titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];

    titleLabel.backgroundColor=[UIColor clearColor];

    titleLabel.font=[UIFont systemFontOfSize:18];

    titleLabel.text=@"Etcast";

    titleLabel.textAlignment=NSTextAlignmentCenter;

    titleLabel.textColor=[UIColor whiteColor];

    item.titleView=titleLabel;

自定义navigationbar

标签:

原文地址:http://www.cnblogs.com/momosmile/p/5032999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!