How to Add UIImageView with UILabel in navigation bar of iphone?

烂漫一生 提交于 2019-12-04 19:33:17

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

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.

iEinstein

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!