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

It's time to change your chopsticks!

Chopsticks, as one of the necessary tableware on ...

Why is it harder to grab red envelopes this year? Plugins are the culprit

The red envelopes developed by the WeChat team in...

How to make money through online promotion?

1. We-media It refers to the general term for new...

Brand Promotion: PR Calendar for May 2019 (Practical Collection)

The holiday is over Everyone voluntarily returned...

The principle and solution of foam formation

Foam is a common phenomenon. Generally speaking, ...

How to plan and promote an excellent event?

Whether you are doing user operations, new media ...

The process and methods of building an activity operation plan!

If you want to obtain more traffic and promote su...

The sun is scorching! What does a "reliable" sun umbrella look like?

The summer is hot, Couples often share an umbrell...

Take stock of the brand marketing methods!

"Brand Brainwashing" mentioned many pop...