我可以将图像提供给导航栏,也可以更改导航栏按钮项的图像。出于某种原因,导航栏图像,我猜,重叠在导航栏按钮图像上。当我单击左侧的导航栏图像但导航栏按钮未显示在导航栏图像上时,导航栏按钮正常工作。这是代码;
UIImage *imagebar = [UIImage imageNamed: @"schedule-strip.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: imagebar];
imageView.frame = CGRectMake(0, 0, 190, 44);
imageView.contentMode = UIViewContentModeScaleAspectFill;
self.navigationItem.titleView = imageView;
UIImage* image = [UIImage imageNamed:@"back-icon.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* someButton = [[UIButton alloc] initWithFrame:frame];
[someButton setBackgroundImage:image forState:UIControlStateNormal];
[someButton setShowsTouchWhenHighlighted:YES];
[someButton addTarget:self action:@selector(backToMore) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* someBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:someButton];
[self.navigationItem setLeftBarButtonItem:someBarButtonItem];
[someBarButtonItem release];
[someButton release];
帮助我。
答案 0 :(得分:2)
使用代码 [imageView addsubView someButton];
我希望你现在会看到这个按钮。实际上你要将左边的按钮项添加到默认导航栏中,当你创建一些按钮时,它没有被添加到与导航栏重叠的imageview上。所以点击该区域它正在工作,但按钮不可见。
答案 1 :(得分:0)
Ketan你检查了图像吗?你的项目中是否存在图像? 为什么要使用导航栏标题的框架和内容模式属性? 愿这个链接帮助你
答案 2 :(得分:0)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"TopBg.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
扩展@interface MyToolBar:UIToolbar并创建MyToolBar的对象。之后,为导航栏创建自定义按钮。享受并喜欢它