2013-01-24 10 views
5

Czy możliwe jest zmniejszenie tekstu tytułu do rozmiaru UINavigationBar w systemie iOS.UINavigationBar title label text

(dla portretowej aplikacji na iPhone bez automatycznego wybierania).

Ustawiam pasek tytułowy dynamicznie, ale czasami tekst jest za długi iw tej chwili po prostu odcina go elipsą.

to znaczy „To jest t ...”

Chciałbym go zamiast kurczyć tekst.

Odpowiedz

8

Możesz utworzyć własny widok tytułowy, aby go utworzyć.

coś takiego:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    //Do any additional setup after loading the view, typically from a nib. 
    UILabel *titleLabelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)]; //<<---- Actually will be auto-resized according to frame of navigation bar; 
    [titleLabelView setBackgroundColor:[UIColor clearColor]]; 
    [titleLabelView setTextAlignment: NSTextAlignmentCenter]; 
    [titleLabelView setTextColor:[UIColor whiteColor]]; 
    [titleLabelView setFont:[UIFont systemFontOfSize: 27]]; //<<--- Greatest font size 
    [titleLabelView setAdjustsFontSizeToFitWidth:YES]; //<<---- Allow shrink 
    // [titleLabelView setAdjustsLetterSpacingToFitWidth:YES]; //<<-- Another option for iOS 6+ 
    titleLabelView.text = @"This is a Title"; 

    navigationBar.topItem.titleView = titleLabelView; 

    //.... 
} 

Nadzieja to pomaga.

+0

Dzięki, faktycznie zrobiłem już coś podobnego. Użyłem kategorii na UILabel, aby utworzyć ją dla mnie szybko we wszystkich kontrolerach widoku. – Fogmeister

2
Xcode 7.1 - Swift 2.0 


//Adding Title Label 
     var navigationTitlelabel = UILabel(frame: CGRectMake(0, 0, 200, 21)) 
     navigationTitlelabel.center = CGPointMake(160, 284) 
     navigationTitlelabel.textAlignment = NSTextAlignment.Center 
     navigationTitlelabel.textColor = UIColor.whiteColor() 
     navigationTitlelabel.text = "WORK ORDER" 
     self.navigationController!.navigationBar.topItem!.titleView = navigationTitlelabel