2016-10-25 3 views
0

Я новичок в iOS. И я столкнулся с проблемой добавить шрифт awesome в UINavigation Bar. Я использую код для изображения Как этоКак добавить шрифт awesome On UINavigation Bar в Objective C

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. Изображение я использую выглядеть следующим образом enter image description here

Я имею Добавить шрифт Высокий, как этот код

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

Но это дает мне ставить, как этот

enter image description here

Шрифт удивительном является надлежащей работой enter image description here

Мне просто нужно добавить шрифт awesome label вместо Image на UINAvigation Bar. Заранее спасибо!

+0

вы можете скрыть свой навигационный блок, а затем вы можете создать свою собственную панель навигации с помощью кнопок «Просмотр» и «Этикетка» и кнопок для этого контроллера представления, в котором вам нужно выполнить над реализацией. – Wolverine

+0

@ Wolverine Но это не работает так же, как UINavigation Bar. – Muju

+0

NavigationBar используется для отображения названия и кнопок. И если вам нужен этот уровень настройки, я предлагаю создать свой собственный вид, который будет выглядеть как ваш желаемый результат. Я не говорю, чтобы удалить навигацию, я говорю «Скрыть NavigatioBar», а затем покажу свое собственное представление. – Wolverine

ответ

1

попробовать, как,

UIImage *listImage4 = [UIImage imageNamed:@"Image2.png"]; 

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 30, 30)]; // desired frame 

[label setFont: [UIFont fontWithName:@"FontAwesome" size:25]]; //desired fornt 


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 setTitle:label.text forState:UIControlStateNormal]; 
// [listButton4 setImage:listImage4 forState:UIControlStateNormal]; 
[listButton4 addTarget:self 
       action:@selector(ActualNotificationClick:) 
     forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *jobsButton4 = 
[[UIBarButtonItem alloc] initWithCustomView:listButton4]; 

Update:

Попробуйте установить attributed string как,

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; 

UIFont *font = [UIFont fontWithName:@"FontAwesome" size:25.0]; 
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font 
                  forKey:NSFontAttributeName]; 
NSAttributedString *attributedStr = [[NSAttributedString alloc] initWithString:@"yourTitleString" attributes:attrsDictionary]; 





[listButton4 setAttributedTitle:attributedStr forState:UIControlStateNormal]; 


[listButton4 addTarget:self 
       action:@selector(ActualNotificationClick:) 
     forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *jobsButton4 = 
[[UIBarButtonItem alloc] initWithCustomView:listButton4]; 

Update 2

UIFont *font = [UIFont fontWithName:@"FontAwesome" size:25.0]; 
UIColor *color = [UIColor whiteColor]; 

NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font 
                  forKey:NSFontAttributeName]; 
[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,color,NSForegroundColorAttributeName, nil]; 

NSAttributedString *attributedStr = [[NSAttributedString alloc] initWithString:@"yourTitleString" attributes:attrsDictionary]; 
+0

newjoinlbl.font = [UIFont fontWithName: @ "FontAwesome" size: 8]; newjoinlbl.textColor = [UIColor whiteColor]; newjoinlbl.text = [NSString awesomeIcon: FaChild]; [listButton2 setTitle: newjoinlbl.text forState: UIControlStateNormal]; Я добавил код Как это – Muju

+0

Пожалуйста, см. Обновленный вопрос – Muju

+0

ваш код дает мне вывод как в вопросе обновления. – Muju

 Смежные вопросы

  • Нет связанных вопросов^_^