tags:

views:

311

answers:

3

Does anyone know how to add a scope bar to a UITableView? The App Store app does this sometimes, like in the picture referenced (I am not allowed to post images, sorry).

I would like to use this scope bar to add sorting options for the elements in the tableview. This would be more convenient than having a toolbar with a segmentedcontrol.

I just don't know how to implement this. I don't even know the name of the element (I'm calling it scope bar because it looks just like the scope bar of a UISearchBar, but it is not).

Thanks in advance.

Picture: http://img27.imageshack.us/img27/6163/img0043a.png

A: 

UISegmentedControl

You create it, set up its segments, and set its delegate. The delegate then takes some sort of action every time the selected segment changes.

Squeegy
A: 

The element is a UISegmentedControl with the UISegmentedControlStyleBar style. You can set the tintColor property to get the color desired. Just put the view above the table view and you can get something that looks like that screenshot.

macatomy
Thanks for that. I just don't know what that tintColor is, do you?
Aloha Silver
You could experiment around until you found something thats similar to the one in the App Store app.
macatomy
+4  A: 

Actually, unlike what others have said, this UISegmentedControl's .segmentedControlStyle property is set to an undocumented value of 7.

 theSegCtrl.segmentedControlStyle = 7;

But @Macatomy's answer is more AppStore-safe (although Apple can't detect this anyway).

KennyTM
That's interesting. How does this undocumented style differ from the documented `UISegmentedControlStyleBar` style?
macatomy
Really interesting. And it really works. It sets the button colors to those pictured, but I don't know of any other differences.And how did you know about that line of code, KennyTM?Thanks.
Aloha Silver
@Aloha: Trial and error :)
KennyTM