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

WeChat cannot send videos over 25MB? Three tips to fix it

As we all know, WeChat has a limit on the size of...

WeChat PC version 3.2.1 released: new video account entry

WeChat updated the computer version 3.2.1 on Marc...

【IT Observation】Methodology for programmers to train new people

[51CTO.com original article] A reader complained ...

WeChat launches a new feature that can remotely lock the screen

Recently, WeChat has launched a new feature in th...

How to do catering marketing? These 16 keywords will tell you!

The term "marketing" has permeated all ...

Tips for making popular short videos!

I have always wanted to interview Zhu Feng to tal...

The four major operating logics of Weibo Super Topic!

There was a "one hundred million" event...

7 Ways to A/B Test Your App Store Pages

If someone tells you that you can increase your a...

The “screenwriter’s mindset” for creating hit short videos

In 2020, the number of creators on the short vide...

How to operate an event? One picture is enough! !

First of all, we must understand that activities ...

up to date! Data rankings of 60 information flow advertising platforms!

Today I bring you the latest traffic rankings of ...

Column on the investment dad's "one trick" strategy

Introduction to the investment dad's "on...