1

我可以将图像提供给导航栏,还可以更改导航栏按钮项的图像。出于某种原因,我猜导航栏图像与导航栏按钮图像重叠。当我单击左侧的导航栏图像时,导航栏按钮正常工作,但它没有显示在导航栏图像上。这是代码;

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]; 

帮帮我。

4

3 回答 3

2

使用代码[imageView addsubView someButton];

我希望现在您会看到该按钮。实际上,您正在将左栏按钮项添加到默认导航栏,并且当您创建某个按钮时,它不会添加到与导航栏重叠的 imageview 上。因此,通过单击该区域它正在工作但按钮不可见。

于 2012-04-09T10:40:44.017 回答
0

Ketan 你检查了图像吗?您的项目中是否存在图像?为什么要为导航栏标题使用框架和内容模式属性?愿此链接对您有所帮助

http://iosdevelopertips.com/user-interface/ios-5-customize-uinavigationbar-and-uibarbuttonitem-with-appearance-api.html

于 2012-04-09T10:01:20.743 回答
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 的对象。之后为导航栏制作自定义按钮。享受并喜欢它

于 2012-04-09T10:07:17.273 回答