在iphone中的UINavigationBar上添加UIImageView

发布于 2024-11-19 17:53:58 字数 168 浏览 0 评论 0原文

我正在 iPhone 上开发一个应用程序。我必须将图像添加到我的视图或 UINavigation 栏上。我的条件是图像将部分添加到导航栏上,部分添加到视图上。

我已将其作为栏按钮项目添加到标题视图中,但其高度受到栏高度的限制。我需要它放在导航栏下方。

如何实施?

提前致谢。

I am developing an application in iphone. I have to add an image on to my view or on UINavigation bar. My condition is that the image will be added partially on navigation bar and partially on view.

I have added it as a barbutton item into titleview but its height is limited by bar height. I need it to drop below navigation bar.

How it can be implemented?

Thanks in advance.

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

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

发布评论

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

评论(4

拥醉 2024-11-26 17:53:58

您可以将图像视图添加为导航栏的子视图,如下所示:

[myNavBar insertSubview:myImageView atIndex:0]; 

You could add the image view as a subview of the navigation bar, something like this:

[myNavBar insertSubview:myImageView atIndex:0]; 
与君绝 2024-11-26 17:53:58

UiNavigatonbar 类的子类:)

subclass UiNavigatonbar class :)

趁微风不噪 2024-11-26 17:53:58
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImageName"]];
    imageView.frame = CGRectMake(100, 0, 200, 80);
    [self.parentViewController.view.window addSubview:imageView];

    [imageView release];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImageName"]];
    imageView.frame = CGRectMake(100, 0, 200, 80);
    [self.parentViewController.view.window addSubview:imageView];

    [imageView release];
寂寞花火° 2024-11-26 17:53:58
#define kWidth [UIScreen mainScreen].bounds.size.width

In the <UIViewController.m>:

- (void)viewDidLoad
{
    UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth-10, 0, 20, 20)];
    titleImageView.image = [UIImage imageNamed:@"The Image Name"];

    titleImageView.contentMode = UIViewContentModeScaleAspectFit;

    self.navigationItem.titleView = titleImageView;
}

它对我有用,对你有用吗?祝你好运!

#define kWidth [UIScreen mainScreen].bounds.size.width

In the <UIViewController.m>:

- (void)viewDidLoad
{
    UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth-10, 0, 20, 20)];
    titleImageView.image = [UIImage imageNamed:@"The Image Name"];

    titleImageView.contentMode = UIViewContentModeScaleAspectFit;

    self.navigationItem.titleView = titleImageView;
}

It works for me , does it work for you ? Good luck!

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