Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-24-2009, 03:10 PM   #17 (permalink)
arsenelpk
Registered Member
 
Join Date: Aug 2009
Posts: 1
arsenelpk is on a distinguished road
Default df

Quote:
Originally Posted by gibson10ma View Post
Ok, so I poked around in the UICatalog sample code for a bit and I managed to make a few changes with the help of the UISlider reference doc. It was surprisingly easy to make the visual changes and increase the CGRect used to track the thumb size. I'll obviously need to adjust these more, but it's a start. This is what I did, and the referenced files are attached. I also attached a pic of how this looks in the simulator.

Code:
- (void)create_Custom_UISlider
{
	CGRect frame = CGRectMake(0.0, 0.0, 300, 52.0);
	CGRect thumb = CGRectMake(0.0, 0.0, 71.0, 47.0);
	customSlider = [[UISlider alloc] initWithFrame:frame];
	[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
	// in case the parent view draws with a custom color or gradient, use a transparent color
	customSlider.backgroundColor = [UIColor clearColor];	
	UIImage *stetchLeftTrack = [[UIImage imageNamed:@"customTrack.png"]
									stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
	UIImage *stetchRightTrack = [[UIImage imageNamed:@"customTrack.png"]
									stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
	[customSlider setThumbImage: [UIImage imageNamed:@"customThumb.png"] forState:UIControlStateNormal];
	[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
	[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
	[customSlider thumbRectForBounds: thumb trackRect: frame value: customSlider.value];
	customSlider.minimumValue = 0.0;
	customSlider.maximumValue = 100.0;
	customSlider.continuous = NO;
	customSlider.value = 5.0;
}
I have a noob question about using this in other apps. And I guess that is - how the heck do I do that? I was thinking I could implement changes to a slider by subclassing UISlider and overriding a few methods. This seems to be what is described in the UISlider reference, but is not what's going on here. I opened the nib file in IB and I can't even find a slider in there. It looks like there stuffing this in a table somehow, but I'm obviously way off track and hoping a more experienced developer can point me in the right direction.

It appears the create_Custom_UISlider: method is being called here:

Code:
- (void)loadView
{	
	[self create_Custom_UISlider];

}
So, this method is being called when loadview is called:, but how does it actually get displayed in the view?

It looks like it's happening in this method:

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath

with this line:

Code:
				// this cell hosts the custom UISlider control
				((DisplayCell *)cell).nameLabel.text = @"Customized Slider";
				((DisplayCell *)cell).view = customSlider;
Ok, so there's a "cell" (whatever that is -- maybe a cell of a table?) and it's "view" is being set to the customSlider. Although I can sort of see what's happening, I don't really understand how to copy this into another application. How do I say "hey main window, plop this sweet custom slider down when you load"??

whew. any thoughts?
df
arsenelpk is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,172
Threads: 93,916
Posts: 402,132
Top Poster: BrianSlick (7,966)
Welcome to our newest member, myrtaah95
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.