1

I want to create an tabBar with 15 items that can be scroll right-left and stop in the middle and not just scrolling each time all the 5 items (320 every time)

I found a code and changed it for displaying 5 items, but when i'm scroll it, all the tab changed and the next tab with 5 items shown, and so on...

- (id)initWithItems:(NSArray *)items {

         self = [super initWithFrame:CGRectMake(0.0, 411.0, 320.0, 49.0)];
         if (self) {
        self.pagingEnabled = YES;
        self.delegate = self;

        self.tabBars = [[[NSMutableArray alloc] init] autorelease];

        float x = 0.0;

        for (double d = 0; d < ceil(items.count / 5.0); d ++) {
            UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(x, 0.0, 320.0, 49.0)];
            tabBar.delegate = self;

            int len = 0;

            for (int i = d * 5; i < d * 5 + 5; i ++)
                if (i < items.count)
                    len ++;

            tabBar.items = [items objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(d * 5, len)]];
            [self addSubview:tabBar];
            [self.tabBars addObject:tabBar];
            [tabBar release];
            x += 320.0;
        }

        self.contentSize = CGSizeMake(x, 49.0);
    }
    return self;
}

How can i create a 'rubber effect' so i can be stop on the 7 item for example.

vadim
  • 119
  • 3
  • 14

1 Answers1

0

You will have to use a different design than the one you quote. If you look at the code carefully you will notice that for each 5 items a new tab bar is created. Clearly, the functionality that you hope for is not feasible with this setup.

The alternative would be to rewrite this with your own UIScrollView. It could be challenging to get exactly the look and feel of the UITabBar, but perhaps that is not such an important constraint. Rather, you would be free to implement your very own design that harmonizes with the look of your app.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Do you have an example of an UIScrollView with some items? Its OK if it wont be like UITabBar, i will design it... – vadim Sep 20 '12 at 13:46
  • Really *any* UIScrollView. Just look at the docs. Set the `contentSize`, insert your buttons or images at the appropriate places, and then you can set the `contentOffset` to show the desired position. With `pagingEnabled` you will have your "rubber effect" (if I understand it right). – Mundi Sep 20 '12 at 14:14