Customize navigation bar with title view

前端 未结 8 2309
一生所求
一生所求 2020-12-08 13:41

I am trying to add a custom view in the center of a navigation bar and I am using the following code to test it:

UIView * testView = [[UIView alloc] init];
[         


        
8条回答
  •  鱼传尺愫
    2020-12-08 14:23

    If you want to just customize the title for one view controller you can use

    UILabel *lblTitle = [[UILabel alloc] init];
    lblTitle.text = @"Diga-nos o motivo";
    lblTitle.backgroundColor = [UIColor clearColor];
    lblTitle.textColor = [UIColor colorWithRed:77.0/255.0 green:77.0/255.0 blue:77.0/255.0 alpha:1.0];
    lblTitle.shadowColor = [UIColor whiteColor];
    lblTitle.shadowOffset = CGSizeMake(0, 1);
    lblTitle.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18.0];
    [lblTitle sizeToFit];
    
    self.navigationItem.titleView = lblTitle;
    

    or if you want to customize for all view controllers use

    [[UINavigationBar appearance] setTitleTextAttributes:
        [NSDictionary dictionaryWithObjectsAndKeys:
            [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], 
            UITextAttributeTextColor, 
            [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], 
            UITextAttributeTextShadowColor, 
            [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], 
            UITextAttributeTextShadowOffset, 
            [UIFont fontWithName:@"Arial-Bold" size:10.0], 
            UITextAttributeFont, 
            nil]];
    

提交回复
热议问题