开发者

How do I implement an "iPhone App Store" style tab bar?

开发者 https://www.devze.com 2023-01-05 03:23 出处:网络
I\'m developing an iPhone app that needs to display fairly complex information, and I think the best way to display it would be to mimic the UI layout that Apple chose in their \"App Store\" app for i

I'm developing an iPhone app that needs to display fairly complex information, and I think the best way to display it would be to mimic the UI layout that Apple chose in their "App Store" app for iPhone.

If you load the App Store app and go to the "top 25" tab, there will be the standard tabs on the bottom (a normal iPhone tab bar) as well as another tab bar on the top containing buttons for "Top Paid", "Top Free", and "Top Grossing".

I'm trying to figure out how to do this two tabbar UI layout, but I can't find anything in the developer documentation for that "top tab bar" control. I've tried manually making a second UITabBar, but it doesn't support adding buttons like in the App Store app.

Does anyone know how to impl开发者_如何学Goement this sort of thing?


The top control in the App Store app is actually a UISegmentedControl. You can create and set its properties as you would most other controls, and set your UINavigationBar's title view to your segmented control.

A quick code example (this goes into your navigation controller's viewDidLoad method):

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]
                                        initWithItems:[NSArray arrayWithObjects:@"One", @"Two", @"Three"]];

// Set the control style so it blends in with the navigation bar
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

// Replace the usual title label with our segmented control
self.navigationItem.titleView = segmentedControl;

[segmentedControl release];

That's of course just for adding the segmented control to the title bar; it's up to you what you want the segmented control to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消