我想在导航栏上添加两个按钮和一个图像视图。我编写了以下代码来添加图像,但它不起作用。
UIView *customView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
UIImageView *logo=[[UIImageView alloc]init];
logo.image=[UIImage imageNamed:@"sdas.jpeg"];
[customView addSubview:logo];
self.navigationController.navigationItem.titleView=customView;
尝试使用initWithCustomView
添加按钮,如此处所述,setBackgroundImage:forMetrics
使用这种方式。
试试这个
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Your Image Name"]];