ios顶部导航栏


顶部导航栏,使用SBScrollNavigation

#pragma mark - SBScrollNavigation

- (NSInteger) numberOfMenuItems {

    if (self.category==nil) {

        CommenData *c= [[CommenData alloc]init];

        self.category=[c getCategory];

    }

    return [self.category count]+1;

}

// Or use a button (DON'T USE BOTH)

- (NSString *) scrollView:(SBScrollNavigation *)scrollView titleForMenuIndex:(NSInteger) index {

    if (index==0) {

        return @"推荐";

    }else{

        return [self.category[index-1] classNames];

    }

}

//

-(NSInteger)getCategoryIndex:(NSInteger) indexC{

    if (indexC==0) {

        return 0;

    }else{

        return [[self.category[indexC-1] classId]intValue];

    }  

}


// Get notified, when a menu Item is selected

- (void) scrollView:(SBScrollNavigation *)scrollView menuItemSelectedAtIndex:(NSInteger) index {

    [[[CommenData alloc]init] setCategoryIndex:[self getCategoryIndex:index]];  

    CGRect r = [[UIScreen mainScreen] applicationFrame];

    self.tableScroll.contentOffset=CGPointMake(r.size.width*index, 0);

}

页面滚动时导航自动变化

/* setSelectedIndex:(NSInteger)index

 *

 * Method to set the selected button. Can

 * be called to programatically set the selected

 * button.

 */

- (void) setSelectedIndex:(NSInteger)index {

  _selectedButton =index;

  UIView *button = [self viewWithTag:_addTag+index];

  [self scrollRectToVisible:button.frame animated:YES];

  [self setNeedsLayout];

  [self layoutIfNeeded];

}


设置导航栏宽度

//设置导航栏宽度


    CGRect r = [[UIScreen mainScreen] applicationFrame];


    self.navigationItem.titleView.frame=CGRectMake(0, 0, r.size.width, 40);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值