Top sliding menu FDSlideBar

Top sliding menu FDSlideBar

Source code introduction: FDSlideBar is a top sliding menu, such as the common styles of NetEase and Tencent News. The control supports multiple styles such as custom colors and fonts. The switching between menus is smooth and has a good experience. After struggling, the content display at the bottom was finally implemented with UITableView, which solved the memory problem of ScrollView well and also obtained a good native sliding effect.

Test environment: Xcode 6.2, iOS 6.0 or above

Source code screenshot:

[[140891]]

Source code snippet:

  1. FDSlideBar *sliderBar = [[FDSlideBar alloc] init];
  2. sliderBar.backgroundColor = [UIColor colorWithRed: 0 / 255.0 green: 128 / 255.0 blue: 128 / 255.0 alpha: 1.0 ];
  3.  
  4. //Init the titles of all the item  
  5. sliderBar.itemsTitle = @[@ "Headlines" , @ "Video" , @ "Shanghai" , @ "Entertainment" , @ "Sports NBA" , @ "Finance" , @ "Technology" , @ "Society" , @ "Military" , @ "Fashion" , @ "Automobile" , @ "Game" , @ "Picture" , @ "Stock" ];
  6.  
  7. // Set some style to the slideBar  
  8. sliderBar.itemColor = [UIColor whiteColor];
  9. sliderBar.itemSelectedColor = [UIColor orangeColor];
  10. sliderBar.sliderColor = [UIColor orangeColor];
  11.  
  12. // Add the callback with the action that any item be selected  
  13. [sliderBar slideBarItemSelectedCallback:^(NSUInteger idx) {
  14. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection: 0 ] atScrollPosition:UITableViewScrollPositionTop animated:NO];
  15. }];
  16. [self.view addSubview:sliderBar];
  17. _slideBar = sliderBar;
  1. // The frame of tableView, be care the width and height property  
  2. CGRect frame = CGRectMake( 0 , 0 , CGRectGetMaxY(self.view.frame) - CGRectGetMaxY(self.slideBar.frame), CGRectGetWidth(self.view.frame));
  3. self.tableView = [[UITableView alloc] initWithFrame:frame];
  4. [self.view addSubview:self.tableView];
  5.  
  6. // Register the custom cell  
  7. UINib *nib = [UINib nibWithNibName:@ "TableViewCell" bundle:nil];
  8. [self.tableView registerNib:nib forCellReuseIdentifier:@ "ContentCell" ];
  9.  
  10. // Set the tableView center in the bottom of view. so after rotating, it shows rightly  
  11. self.tableView.center = CGPointMake(CGRectGetWidth(self.view.frame) * 0.5 , CGRectGetHeight(self.view.frame) * 0.5 + CGRectGetMaxY(self.slideBar.frame) * 0.5 );
  12. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  13.  
  14. // Rotate the tableView 90 angle anticlockwise  
  15. self.tableView.transform = CGAffineTransformMakeRotation(-M_PI_2);
  16. self.tableView.showsVerticalScrollIndicator = NO;
  17. self.tableView.pagingEnabled = YES;
  18. self.tableView.dataSource = self;
  19. self.tableView.delegate = self;
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2. TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@ "ContentCell" ];
  3.  
  4. // Rotate the cell's content 90 angle clockwise to show them rightly  
  5. cell.contentView.transform = CGAffineTransformMakeRotation(M_PI_2);
  6. cell.text = self.slideBar.itemsTitle[indexPath.row];
  7. return cell;
  8. }

Download address: http://download..com/data/2068577

<<:  Like effect button

>>:  iOS 9 Learn more every day Day 1: Search API

Recommend

"Cultural Relics Doctor" - Microorganisms

Cultural relics, as the historical accumulation o...

Zendesk: 2024 Customer Experience Trends Report

Zendesk released the "2024 Customer Experien...

Youth Physical Fitness Course Baidu Cloud Download

Youth Physical Fitness Course Resources Introduct...

37 tips from Ogilvy's creative director for advertisers

A few days ago, I happened to see several quotes ...

The i7-3960X has become a "foreign garbage": Can it drive the GTX 1080?

Many people think that playing games only require...

Don't sleep, wake up! I'm hibernating

Have you noticed that after a large wave of rainf...