ios中navigationItem的titleView如何居中
ios中navigationItem的titleView如何居中
SunGiantor 发表于3年前
ios中navigationItem的titleView如何居中
  • 发表于 3年前
  • 阅读 4878
  • 收藏 1
  • 点赞 0
  • 评论 0

移动开发云端新模式探索实践 >>>   


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;

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 14
博文 55
码字总数 20782
×
SunGiantor
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: