Lalit Paliwal
Lalit Paliwal

Reputation: 723

Add UIImageView on UINavigationBar in iphone

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.

Upvotes: 2

Views: 1953

Answers (4)

AaronTKD
AaronTKD

Reputation: 109

#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!

Upvotes: 0

med200
med200

Reputation: 222

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

[myNavBar insertSubview:myImageView atIndex:0]; 

Upvotes: 1

Alex Terente
Alex Terente

Reputation: 12036

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

    [imageView release];

Upvotes: 0

Abdurrashid Khatri
Abdurrashid Khatri

Reputation: 338

subclass UiNavigatonbar class :)

Upvotes: 0

Related Questions