1

I have some navigation bar in my UI of iphone app. Now i want to add two images on the navigation bar on center of the navigation bar.. I have successfully added the two UIImageView on the navigation-bar but my problem is that i have two UIImageView with the label on it ..

Let me show u the snapshot ...enter image description here

now my problem is i don't know how to add this kind of label near UIImageView in navigation bar..so please if anyone can guide me for this then it will help me a lot..

i have already successfully inserted two images on navigation bar with this Code.

   UIImageView *Messageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed :"message.png"]];
        Messageview.frame=CGRectMake(10, 0, 40, 40);

        UIImageView *BirthdayView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:"birthday.png"]];
        //titleView.frame=CGRectMake(60, 0, 50, 50);

UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    [flexible setWidth:20];
    UIBarButtonItem *flexible1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    [flexible setWidth:20];


        UIBarButtonItem *MessageBtn=[[UIBarButtonItem alloc]initWithCustomView:Messageview];

        UIBarButtonItem *BirthdayBtn=[[UIBarButtonItem alloc]initWithCustomView:BirthdayView];
        self.navigationItem.rightBarButtonItems=[NSArray arrayWithObjects:rofileBtn,flexible,BirthdayBtn,MessageBtn,flexible1,nil];

Please Guide me as soon as possible..

Venk
  • 5,949
  • 9
  • 41
  • 52
BhavikKama
  • 8,566
  • 12
  • 94
  • 164
  • u set cutom view in navigation bar and set default navigation bar hidden – kirti Chavda Jun 03 '13 at 05:26
  • make a customView---- for your navigation bar and set Default navigation bar hiddenn...\ – alpha Jun 03 '13 at 05:28
  • i cant set custom view..because the left-side button of navigation bar is always must be there as there is a one side bar will open on click of that left-side button... – BhavikKama Jun 03 '13 at 05:28

3 Answers3

5

possible duplicate. see here. It seems you need to inherit UIBarButtonItem and create your own custom view with a UIButton with a subview of the badge you need to add. Hope it helps.

Community
  • 1
  • 1
aliirz
  • 1,008
  • 2
  • 13
  • 25
2

Please use this

UILabel *labelforNavigationTitle = [[UILabel alloc] initWithFrame:CGRectZero];
labelforNavigationTitle.font = [UIFont fontWithName:FONTSAVINGSBOND size:30.0];//SavingsBond
labelforNavigationTitle.backgroundColor = [UIColor clearColor];  
labelforNavigationTitle.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
labelforNavigationTitle.textAlignment = UITextAlignmentCenter;
labelforNavigationTitle.textColor = [UIColor whiteColor]; // change this color

labelforNavigationTitle.text = NSLocalizedString(@"Text you want", @"");
self.navigationItem.titleView = labelforNavigationTitle;
[labelforNavigationTitle sizeToFit];

Please use this code by setting the frame according to you images. Because you have already added images to your project, just put the label next to them wherever you want.

Hope this helps.

Anil
  • 2,430
  • 3
  • 37
  • 55
iEinstein
  • 2,100
  • 1
  • 21
  • 32
2

I think this would help you.

 UIView *msgView=[[UIView alloc]initWithFrame:CGRectMake(10, 0, 40, 40)];
    UIImageView *Messageview =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"message.png"]];

    Messageview.frame=CGRectMake(0, 0, 20, 20);

    [msgView addSubview:Messageview];

    UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(30, 0, 20, 20)];
    [lbl setText:@"Text"];
    [msgView addSubview:lbl];
UIBarButtonItem *MessageBtn=[[UIBarButtonItem alloc]initWithCustomView:msgView];
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86