码迷,mamicode.com
首页 > 移动开发 > 详细

ios中navigationItem的titleView如何居中

时间:2015-06-14 21:30:38      阅读:449      评论:0      收藏:0      [点我收藏+]

标签:

CGRect rect = [UIScreen mainScreen].bounds;

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

    _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, 30);

    [_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, 30);

    [_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如何居中

标签:

原文地址:http://my.oschina.net/u/2252309/blog/466620

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!