I am interested in creating a menu bar like this:
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!
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.
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 normallyDrag
tabs can quickly move pagesClick
a tab to change to that pageThe 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 :)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With