Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creation of a Horizontal Infinite Scrolling Menu Bar in iOS

I am interested in creating a menu bar like this:

Menu Bar Example

From what I have been reading, I should be doing a UIScrollView. Are there any examples online that do this with infinite scrolling (wrapping around the menu bar) and the ability to have touch control? (i.e. swipe and it changes the menu bar).

Thanks!

like image 243
lele0108 Avatar asked Nov 09 '14 18:11

lele0108


People also ask

What is scrollable horizontal menu?

Approach: Scrollable Horizontal Menu is used to scroll the horizontal navbar using CSS “overflow:auto” and “white-space: nowrap”. These two attributes are used to scroll the horizontal menu. To implement the scrollable horizontal menu. You have to add HTML. You have to add CSS to the code.


Video Answer


2 Answers

Your request is very similar to mine. But I cannot find a good enough solution too. So I decide to create something to do that by myself.

The ACTabScrollView supports some different gestures. And the tabs and pages will always scroll synchronously.

  • Swipe pages normally
  • Drag tabs can quickly move pages
  • Click a tab to change to that page

demo1demo2demo3

The Infinite Scrolling feature is not ready yet, but I will keep to implement.

I use the similar UI as examples in this project. I don't know what the app is, but if using it as an example bother anyone. Contact me and I will immediately remove that.

Feel free to give me any suggestion to improve it :)

like image 131
Azure Chen Avatar answered Oct 18 '22 18:10

Azure Chen


I hope this code will work for you.

- (void)viewDidLoad
{
 [super viewDidLoad];
 [self createHorizontalScroll];
}

- (void)createHorizontalScroll
{
   UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 80, self.view.frame.size.width, 80)];

   int buttonX = 0;
   for (int i = 0; i < 5; i++)
   {
     UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(buttonX, 0, 100, 60)];
    [button setTitle:[NSString stringWithFormat:@"Button %d", i] forState:UIControlStateNormal];
    [scrollView addSubview:button];
    buttonX = buttonX+button.frame.size.width;
    [button addTarget:self
               action:@selector(changeView:)
     forControlEvents:UIControlEventTouchUpInside];

   }

scrollView.contentSize = CGSizeMake(buttonX, scrollView.frame.size.height);
scrollView.backgroundColor = [UIColor greenColor];
[self.view addSubview:scrollView];

}

 -(void)changeView:(UIButton*)sender
 {
   NSLog(@"I Clicked a button %ld",(long)sender.tag);
 }

You can set scroll content as much you want and menu buttons.Change the view according to the button click. Here the screen shot of the above code

enter image description here

like image 24
Shrikant K Avatar answered Oct 18 '22 18:10

Shrikant K