[英]How to Add UIImageView with UILabel in navigation bar of iphone?
我的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];
请尽快指导我。
可能重复。 看这里 。 似乎您需要继承UIBarButtonItem
并使用带有要添加的徽章的子视图的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];
请根据您的图像设置框架来使用此代码。 由于您已经将图像添加到了项目中,因此只需将标签放在它们旁边即可。
希望这可以帮助。
我认为这对您有帮助。
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.