自定义UINavigationBar

不使用UINavigationController用代码自定义UINavigationBar和样式

屏幕快照 2015-08-13 14.27.54.png


UINavigationBar *bar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 60)];
    UIBarButtonItem *leftbutton=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"left_view.png"] style:UIBarButtonItemStylePlain target:self action:@selector(showLeftView)];
     UIBarButtonItem *rightButton=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"left_view.png"] style:UIBarButtonItemStylePlain target:self action:@selector(initPopMenu)];
    UINavigationItem *item=[[UINavigationItem alloc]initWithTitle:@"首页"];
    [item setLeftBarButtonItem:leftbutton];
    [item setRightBarButtonItem:rightButton];
    [bar pushNavigationItem:item animated:false];
    [self.View addSubview:bar];

如果没有效果,是因为你没有定义left_view.png这个图片

Last modification:January 1st, 1970 at 08:00 am
如果看了这个文章可以让你少加会班,可以请我喝杯可乐
已打赏名单
微信公众号

Leave a Comment