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

Annual server rental bandwidth cost for short videos

In the era of selling goods by all, short videos ...

Why would anyone like to eat Houttuynia cordata?

When talking about Houttuynia cordata, the first ...

8 tips for through train promotion

Through train promotion skills Many people feel t...

User growth: How to establish a user perspective?

What is the user perspective? This is actually a ...

Little Red Book video notes operation tips!

2021 will still be a year of rapid development fo...

A new way to innovate e-commerce - earn money by buying in groups!

When I was talking with a friend last week, I cam...

How to choose channels for app soft promotion?

There is another big pitfall in App soft promotio...

If your eyes feel "tired", it is actually reminding you...

Dry eyes, sore eyes, swollen eyes, As I read the ...

The key points of KFC’s “Crazy Thursday” marketing!

A day or two ago, KFC successfully registered &qu...