ToB

类似这样的导航栏  用WKBarButtonUtil那个框架:

- (void)initNav
{
    //必要的设置, 如果没有设置可能导致内容显示不正常
    //    self.edgesForExtendedLayout = UIRectEdgeNone;

    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.frame = CGRectMake(10, 35/2.0f, 60, 40);
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -30);
    btn.titleLabel.textAlignment = NSTextAlignmentLeft;
    btn.mj_y = _segment.mj_y-7;
    btn.width = 100;
    
    [btn setTitle:@"杭州" forState:UIControlStateNormal];
    
    [btn setImage:[UIImage imageNamed:@"rightRow_home"] forState:UIControlStateNormal];
    CGSize titleSize = self.cBtnLeft.titleLabel.bounds.size;
    CGSize imageSize = self.cBtnLeft.imageView.bounds.size;
    //文字左移
    btn.titleEdgeInsets = UIEdgeInsetsMake(0.0, -imageSize.width-10, 0.0, 60);
    //    UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
    //图片右移
    btn.imageEdgeInsets = UIEdgeInsetsMake(0.0, titleSize.width, 0.0, -titleSize.width);
    btn.titleLabel.font = Font(12.0);
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = [WKBarButtonUtil barButtonWithImage:Image(@"rightRow_home") target:self action:@selector(navRightPressed)];
    [btn addTarget:self action:@selector(navLeftPressed) forControlEvents:UIControlEventTouchUpInside];

    self.segment = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"优选",@"咨询"]];
    _segment.frame =CGRectMake(0, 20, 120, 44);
    _segment.verticalDividerWidth = 10;
    _segment.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    NSLog(@"segment.frame%@",NSStringFromCGRect(_segment.frame));
    NSLog(@"selectionIndicatorHeight%f",_segment.selectionIndicatorHeight);
    _segment.selectionIndicatorHeight = 2.0f;
    _segment.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    _segment.selectionIndicatorColor = [UIColor redColor];
    _segment.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor blackColor]};
    _segment.selectedTitleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor redColor]};
    _segment.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
    [_segment addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
    self.navigationItem.titleView = self.segment;
 
    UIView *line = [[UIView alloc] init];
    line.frame = (CGRect){0,K_NAV_HEIGHT-1,K_SCREEN_WIDTH,1};
    line.backgroundColor = COLORE_BACKGROUNDCOLOR_LIGHTGRAY;
    
    
    //试验居中
    CGRect leftViewbounds = self.navigationItem.leftBarButtonItem.customView.bounds;
    
    CGRect rightViewbounds = self.navigationItem.rightBarButtonItem.customView.bounds;
    
    
    
    CGRect frame;
    
    CGFloat maxWidth = leftViewbounds.size.width > rightViewbounds.size.width ? leftViewbounds.size.width : rightViewbounds.size.width;
    
    maxWidth += 15;//leftview 左右都有间隙,左边是5像素,右边是8像素,加2个像素的阀值 5 + 8 + 2
    
    
    
    frame = _segment.frame;
    
    frame.size.width = K_SCREEN_WIDTH - maxWidth * 2;
    
    self.navigationItem.titleView.frame = frame;
    
    
    
    frame = _segment.frame;
    
    frame.size.width = K_SCREEN_WIDTH - maxWidth * 2;
    
    _segment.frame = frame;
    

}

- (void)createUI
{

    
    
   
}
- (void)navLeftPressed
{
    NSLog(@"clickleft");
}

- (void)navRightPressed
{
    NSLog(@"clickRight");
}
- (void)navRightPressed:(UIButton *)sender
{
    
}
- (void)segmentedControlChangedValue:(HMSegmentedControl *)sender
{
    
}

缺点:HMSegment下面的线不能如设计稿缩短,暂时先这样待优化.或自己写或找博客

简易修改那条红线可参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值