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

How to build e-commerce live streaming 0-1?

How did a successful e-commerce live broadcast co...

Some tips about mobile phone screens

Let's talk about screen replacement, save it ...

Astronomy, the science closest to us and yet farthest away, what is its use?

Produced by: Science Popularization China Author:...

How to set keywords for Xiaohongshu promotion notes!

On the Xiaohongshu platform, taking good notes is...

Review: 27 fans pushed the second time, how did I achieve 1,600 readers

I am a novice when it comes to operating a public...

What did a 5,000-year-old jade mask look like?

"This jade mask is a kind of funeral jade. T...

How to take advantage of the hot summer season to advertise?

In the advertising market, how to seize special o...

Are the “notorious” trans fatty acids really something we cannot touch?

Ruan Guangfeng Cheese and cheese sticks have been...

Android 9.0 upgrade is too slow, Google wants users to test Android Q directly

Although after Google released Android 9.0 this y...