ios中navigationItem的titleView如何居中


CGRect rect = [UIScreen mainScreen].bounds;

    _friendsCircleTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,140, 29)];

    _friendsCircleTitleView.backgroundColor = [UIColor clearColor];

    _friendsCircleTitleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

    

    _friendsCircleTitleView.autoresizesSubviews = YES;

    

    

    _sameCityBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    _sameCityBtn.backgroundColor = [UIColor clearColor];

    _sameCityBtn.frame = CGRectMake(0, 0, 70, 29);

    [_sameCityBtn setTitle: @"同城" forState: UIControlStateNormal];

    [_sameCityBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];

    [_sameCityBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateHighlighted];

    _sameCityBtn.titleLabel.font = [UIFont boldSystemFontOfSize: 13.0];

    [_sameCityBtn setBackgroundImage:[UIImage imageNamed:@"sameCity"] forState: UIControlStateNormal];

    [_sameCityBtn setBackgroundImage:[UIImage imageNamed: @"sameCitySelected"] forState: UIControlStateHighlighted];

    [_sameCityBtn setBackgroundImage:[UIImage imageNamed: @"sameCitySelected"] forState: UIControlStateSelected];

    _sameCityBtn.tag = TAG_OF_SAMECITY_BTN;

    [_sameCityBtn addTarget:self action:@selector(onLeftTitleBtnPressed) forControlEvents:UIControlEventTouchUpInside];

    [_friendsCircleTitleView addSubview: _sameCityBtn];

    _sameCityBtn.selected = YES;

    _sameCityBtn.userInteractionEnabled = NO;

    

    _wholeCountryBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    _wholeCountryBtn.backgroundColor = [UIColor clearColor];

    _wholeCountryBtn.frame = CGRectMake(_sameCityBtn.frame.origin.x+70, 0, 70, 29);

    [_wholeCountryBtn setTitle:@"全国" forState: UIControlStateNormal];

    [_wholeCountryBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];

    [_wholeCountryBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateHighlighted];

    _wholeCountryBtn.titleLabel.font = [UIFont boldSystemFontOfSize:13.0f];

    [_wholeCountryBtn setBackgroundImage:[UIImage imageNamed: @"wholeCountryNomal"] forState:UIControlStateNormal];

    [_wholeCountryBtn setBackgroundImage:[UIImage imageNamed: @"wholeCountrySelected"] forState: UIControlStateHighlighted];

    [_wholeCountryBtn setBackgroundImage:[UIImage imageNamed: @"wholeCountrySelected"] forState: UIControlStateSelected];

    _wholeCountryBtn.tag = TAG_OF_WHOLECOUNTY_BTN;

    [_wholeCountryBtn addTarget:self action:@selector(onRightTitleBtnPressed) forControlEvents:UIControlEventTouchUpInside];

    [_friendsCircleTitleView addSubview:_wholeCountryBtn];

    _wholeCountryBtn.selected = NO;

   

        self.navigationItem.titleView = _friendsCircleTitleView;

你可能感兴趣的:(ios中navigationItem的titleView如何居中)