Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dgdosen

macrumors 68030
Original poster
Dec 13, 2003
2,858
1,497
Seattle
So, if you look at the Stocks' App, the graph on the bottom has a series of buttons across the top with different time frames (1d, 1w, 1m, 3m...) Anybody know how that was implemented?

UIToolBar?
UIButtons?

I especially like how the buttons invert when selected...

I'm sure there's an easy way to do this, I just need to be shown the way. If anyone can do that, it would be greatly appreciated...
 
Well it seems to behave more like a UISegmentedControl than a UIToolbar.
But since it is so graphically different than a UISegmentedControl it might just be a bunch of customUIButtons.

If all you want is the functionality and not so much the specific look, look into UISegmentedControl.

On the 4th screen shot of my app you can see how I implemented it (graphically).
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284946807&mt=8

Here's some code for it:

Code:
	NSArray *segmentTextContent = [NSArray arrayWithObjects: @"About", @"Tutorials", @"Index", @"Web", nil];
	UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
	segmentedControl.frame = CGRectMake((320-255)/2.0, 34, 255, 30);
	[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
	segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
	segmentedControl.selectedSegmentIndex = 0; //About
	segmentedControl.tintColor = [UIColor colorWithRed:130/255.0 green:91/255.0 blue:66/255.0 alpha:1]; //Dark brown
	
	[self.view addSubview:segmentedControl]; // add to view
	[segmentedControl release];

and then


Code:
- (void)segmentAction:(id)sender  
{ //Note: this might be better with a case statement, but it works
	if([sender selectedSegmentIndex] == 0)
	{		
	}
	else if([sender selectedSegmentIndex] == 1)
	{
	}
	else if([sender selectedSegmentIndex] == 2)
	{
	}
	else if([sender selectedSegmentIndex] == 3)
	{
	}
}


Hope that helps.
Josh
 
I just implemented it (or am implementing it) using the UIButtons - of which I haven't worked much with yet.

It was pretty easy to create them in a nib and implementing them using the roundedrectangle approach. That works well, but I really don't want to localize nib files and if I do things the stock app way - I'd have to change the graph buttons based on language.

Therefore, I'm just creating everything in code and foregoing the nib file. So far, so good...
 
Yeah, I've always constructed GUIs programmatically. I don't have any credentials to recommend either way though.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.