无法在导航栏中设置完整图像

发布于 2024-11-06 10:14:10 字数 898 浏览 1 评论 0原文

我无法在导航栏(或应用程序顶部的导航控制器)中设置完整图像。左侧将剩下很少的空间。当我放置信息按钮时,它不在图像上。我该如何解决这个问题,

这是我的代码,请看一下,

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]];
    img.frame = CGRectMake(0, 0, 320, 44);
    self.navigationItem.titleView =img;
    [img release];


UIButton * infoDarkButtonType = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
     infoDarkButtonType.frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
     infoDarkButtonType.backgroundColor = [UIColor clearColor];
     [infoDarkButtonType addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside];
     UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:infoDarkButtonType];
     self.navigationItem.leftBarButtonItem = infoButton;
     [infoDarkButtonType release];
     [infoButton release];

非常感谢。

我。

I can't set full image in navigation bar (or navigation controller ,in the top of app). there will be little space remaining in the left.And when I put info button it's not on the image. How can I fix it

here is my code,pls take a look

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]];
    img.frame = CGRectMake(0, 0, 320, 44);
    self.navigationItem.titleView =img;
    [img release];


UIButton * infoDarkButtonType = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
     infoDarkButtonType.frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
     infoDarkButtonType.backgroundColor = [UIColor clearColor];
     [infoDarkButtonType addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside];
     UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:infoDarkButtonType];
     self.navigationItem.leftBarButtonItem = infoButton;
     [infoDarkButtonType release];
     [infoButton release];

very thank you.

Me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-11-13 10:14:10

如果你想让导航栏显示图像你不能尝试这个

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect
{
  UIImage *image = [UIImage imageNamed: @"custom_nav_bar.png"];
  [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

If you want the navigation bar to show an image cant you try this

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect
{
  UIImage *image = [UIImage imageNamed: @"custom_nav_bar.png"];
  [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
吹梦到西洲 2024-11-13 10:14:10

使用此代码行在 NavigationController 中添加图像...

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]];
img.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationItem addSubView:img];
[img release];

现在,您在导航中设置图像..

Use this code line ot add image in NavigationController...

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]];
img.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationItem addSubView:img];
[img release];

now, you set image in Navigation..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文