我是 iOS 新手。我在 UINavigation Bar 上添加很棒的字体时遇到了问题。我正在使用像这样的图像代码
UIImage *listImage2 = [UIImage imageNamed:@"Image1.png"];
UIButton *listButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect listButton2Frame = listButton2.frame;
listButton2Frame.size = listImage2.size;
listButton2.frame = listButton2Frame;
[listButton2 setImage:listImage2 forState:UIControlStateNormal];
[listButton2 addTarget:self
action:@selector(LogoutClick:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton2 =
[[UIBarButtonItem alloc] initWithCustomView:listButton2];
UIImage *listImage4 = [UIImage imageNamed:@"Image2.png"];
UIButton *listButton4 = [UIButton buttonWithType:UIButtonTypeCustom];
// get the image size and apply it to the button frame
CGRect listButton4Frame = listButton4.frame;
listButton4Frame.size = listImage4.size;
listButton4.frame = listButton4Frame;
[listButton4 setImage:listImage4 forState:UIControlStateNormal];
[listButton4 addTarget:self
action:@selector(ActualNotificationClick:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton4 =
[[UIBarButtonItem alloc] initWithCustomView:listButton4];
UIImage *listImage3 = [UIImage imageNamed:@"Image3.png"];
UIButton *listButton3 = [UIButton buttonWithType:UIButtonTypeCustom];
// get the image size and apply it to the button frame
CGRect listButton3Frame = listButton3.frame;
listButton3Frame.size = listImage3.size;
listButton3.frame = listButton3Frame;
[listButton3 setImage:listImage3 forState:UIControlStateNormal];
[listButton3 addTarget:self
action:@selector(EmployeeClick:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton3 =
[[UIBarButtonItem alloc] initWithCustomView:listButton3];
self.navigationItem.rightBarButtonItems= [NSArray arrayWithObjects:jobsButton2,jobsButton4, nil];
self.navigationItem.leftBarButtonItems=[NSArray arrayWithObjects:jobsButton3, nil];
对于字体真棒我正在使用这样的代码
lab.font = [UIFont fontWithName:@"FontAwesome" size:25];
lab.textColor = [UIColor whiteColor];
lab.text = [NSString awesomeIcon:FaCalendarChecko];
我需要在 UINavigation Bar 上添加字体真棒标签而不是图像。我使用的图像看起来像这样
我有像这段代码一样添加字体真棒
newjoinlbl.font = [UIFont fontWithName:@"FontAwesome" size:8];
newjoinlbl.textColor = [UIColor whiteColor];
newjoinlbl.text = [NSString awesomeIcon:FaChild];
UIButton *listButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
// get the image size and apply it to the button frame
CGRect listButton2Frame = listButton2.frame;
listButton2Frame.size = listImage2.size;
listButton2.frame = listButton2Frame;
[listButton2 setTitle:newjoinlbl.text forState:UIControlStateNormal];
[listButton2 addTarget:self
action:@selector(LogoutClick:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton2 =
[[UIBarButtonItem alloc] initWithCustomView:listButton2];
但它让我像这样
我只需要在 UIAvigation Bar 上添加字体真棒标签而不是图像。提前致谢!