如何在Uphone的导航栏中添加UILabel UIImageView?

我的iphone应用程序UI中有一些导航栏。 现在我想在导航栏中心的导航栏上添加两个图像..我已经在导航栏上成功添加了两个UIImageView但我的问题是我有两个带有标签的UIImageView ..

让我告诉你快照…… 在此处输入图像描述

现在我的问题是我不知道如何在导航栏中的UIImageView附近添加这种标签..所以,如果有人可以指导我这个,那么它将帮助我很多..

我已经使用此代码在导航栏上成功插入了两个图像。

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

请尽快指导我..

我想这会对你有所帮助。

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

可能重复。 看到这里 。 您似乎需要inheritanceUIBarButtonItem并使用UIButton创建自己的自定义视图,其中包含您需要添加的徽章的子视图。 希望能帮助到你。

请用这个

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

请根据您的图像设置框架使用此代码。 因为您已经将图像添加到项目中,所以只需将标签放在它们旁边的任何位置即可。

希望这可以帮助。