2016-04-26 2 views
1

enter image description hereНавигационная панель выравнивания название

[[UIBarButtonItem appearance] 

    setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; 
     [self.navigationController.navigationBar setTitleTextAttributes: 
     @{NSForegroundColorAttributeName:RED_COLOR ,NSFontAttributeName:[UIFont fontWithName:@"OpenSans-Semibold" size:16]}]; 
     [email protected]"ORDER DETAILS"; 

Я использую приведенный выше код, чтобы установить название для просмотра контроллера, но название не идет должным образом. В каком-то виде контроллере он приходит, как ожидается,

+0

см эту ссылку, он может помочь вам http://stackoverflow.com/questions/26903013/ navigationbar-title-alignment-issue –

+0

Вы можете создать свой собственный ярлык и добавить в название заголовка панели навигации, установить нужный вам выравнивание. – Elangovan

+0

@Elangovan Мне не нужно настраивать ярлык – vijeesh

ответ

1
// here to create a UILabel 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; 
    label.backgroundColor = [UIColor clearColor]; 
    label.textColor = [UIColor blackColor]; 
    label.numberOfLines = 1; 
// set your custom font for title 

    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"ORDER DETAILS"]; 
    [string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0,5)]; 

// set line spacing 
    NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init]; 
    [paragrahStyle setLineSpacing:6]; 
    [paragrahStyle setAlignment:NSTextAlignmentCenter]; 
    [string addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:NSMakeRange(0, [string length])]; 

    label.attributedText = string; 
    [label sizeToFit]; 
    self.navigationItem.titleView = label; 

скопирован из: Navigationbar title alignment issue

или еще лучше идея сделала название как UIImage, и вы можете использовать это изображение в качестве заголовка панели навигации. Используйте изображение размером 44x44 точек с размером 2x и 3x.

UIImageView* titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Orderpng.png"]]; 
imageView.contentMode = UIViewContentModeScaleAspectFit; 

UIView* titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; 
imageView.frame = titleView.bounds; 
[titleView addSubview:imageView]; 

self.navigationItem.titleView = titleView; 

наслаждаться кодирования :)

0

Для тех, кто ищет Xamarin Решение:

var label = new UILabel(); 
      label.Text = title; 
      label.Font = UIFont.FromName(Strings.OpenSans_Bold, 30f);//This is a custom font. You will have to add it to your project first. 
      label.TextAlignment = UITextAlignment.Left; 
      label.SizeToFit(); 
      NavigationController.NavigationBar.TopItem.LeftBarButtonItem = new UIBarButtonItem(label); 
Смежные вопросы