Adjusting navigationItem.titleView's frame?

前端 未结 13 1566
小蘑菇
小蘑菇 2021-01-31 04:14

I noticed that the titleView\'s position depends on the rightbarbutton title. How can I set the frame of the titleView to be in the center instead?

I\'ve tried setting

13条回答
  •  余生分开走
    2021-01-31 04:43

    -(void) awakeFromNib
    {
        UIButton *titleLabel = [UIButton buttonWithType:UIButtonTypeCustom];
        [titleLabel setTitle:@"Right Eye" forState:UIControlStateNormal];
        [titleLabel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [titleLabel setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
        titleLabel.titleLabel.backgroundColor = [UIColor clearColor];
        titleLabel.titleLabel.font = [UIFont boldSystemFontOfSize:20.0];
        titleLabel.titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.3];
        [titleLabel addTarget:self action:@selector(titleTap:) forControlEvents:UIControlEventTouchUpInside];
        titleLabel.frame = CGRectMake(0, 0, 400, 20);
        self.navigationItem.titleView = titleLabel;
    
    }
    

提交回复
热议问题