show all tabs with scrolling option (on screen there should be only 4 tabs)

只谈情不闲聊 提交于 2019-12-18 09:33:23

问题


I am newbie for iOS development. What I have done so far is as below.

  1. Created New Project
  2. Removed all controller and added View Controller.
  3. Dragged ScrollView in ViewController
  4. Dragged Tab Bar in ScrollView
  5. Dragged 7 Tab Bar Item in Tab Bar.

Now when I execute this project, I have all 7 tabs on screen which is not looking good. So what I am planning is display only 4 tab at first and if user scroll it horizontally, user can scroll and see rest tabs.

So, what I want to achieve is programmatically set some parameter in ScrollView that it will display only first 4 options only.

Any idea/ suggestion on this to be done?


回答1:


EDIT :

I think this one may be even more adapted to the situation. Contrary to KLHorizontalSelect, it's kind of old (no commit on the master branch for a year ?) and I have no experience with it, but it may solve your problem : InfiniTabBar.

The description is short :

A scrolling tab bar with space for infinite items


Maybe you can take a look at this control : KLHorizontalSelect.

Here's how it looks like :

I don't think it looks exactly as you want, but I think it works almost as what you're expecting. Maybe you can work on the design ?




回答2:


You have no code used so far, but you'll absolutely have to do that to achieve this. I'll get you started:

Create a scrollview at the bottom of your viewcontroller. Create UIViews on it and make them have a width of 640 (iPhone Retina screen width). You can put a image and a title on the UIView and make them function as a button. Set the content size to 640/4 *7 and there you go. You can give the background of the scrollview the same image as the UITabBar, but you'll need this.

This snippet might help you:

for (int i = 0; i<7; i++){
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0 + 50*i,0, 50,50);
    [scrollView addSubview:view];
}

You'll have to multiply the x origin with the width of the UIViews (plus some margin) to make sure they aren't all on the same spot.



来源:https://stackoverflow.com/questions/13743777/show-all-tabs-with-scrolling-option-on-screen-there-should-be-only-4-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!