您的位置:首页 > 其它

自定义navigationbar

2015-12-09 15:32 441 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: