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

MTShipp

macrumors 6502a
Original poster
Mar 25, 2009
826
183
Raleigh, North Carolina
Is there a way to make the sliders wider? In other words, make them easier for people with large fingers to use or poor eyesight to see them? I know how to lengthen them but is there a way to increase their size so they appear larger?
 

justfred

macrumors newbie
May 8, 2009
21
0
after a quick search:

trackRectForBounds:
Returns the drawing rectangle for the slider’s track.

Code:
- (CGRect)trackRectForBounds:(CGRect)bounds

Parameters
bounds
The bounding rectangle of the receiver.

Return Value
The computed drawing rectangle for the track. This rectangle corresponds to the entire length of the track between the minimum and maximum value images.

Discussion
You should not call this method directly. If you want to customize the track rectangle, you can override this method and return a different rectangle. The returned rectangle is used to scale the track and thumb images during drawing.

Availability
Available in iPhone OS 2.0 and later.
Declared In
UISlider.h

http://developer.apple.com/iphone/l...le_ref/occ/instm/UISlider/trackRectForBounds:
 

MTShipp

macrumors 6502a
Original poster
Mar 25, 2009
826
183
Raleigh, North Carolina
mpatric,

I am trying to implement your slider code and can not get it to work. I am a n00b anyway.

I created the MySlider.h and .m and copied your code in. I then added the #import "MySlider.h" to my other files.

- (IBAction)MySlider:(id)sender {
MySlider *slider = (MySlider *)sender;
int progressAsInt = (int)(slider.value + 0.5f);
NSString *newText = [[NSString alloc] initWithFormat:mad:"%d", progressAsInt];

...rest of code....

}

I connected the slider and then executed but it does not change anything. It still uses the default bounding box areas. I even added a NSLog to the pointInside part and it never shows up in the console.
 

MTShipp

macrumors 6502a
Original poster
Mar 25, 2009
826
183
Raleigh, North Carolina
This is from my code. I can not get the slider to work with larger bounds. The slider moves and feedsback the data from MysliderCal but the processing from mpatric isn't working.


MySlider.h

Code:
#import <UIKit/UIKit.h>
@interface MySlider : UISlider {
}
@end

MySlider.m

Code:
#import "MySlider.h"
#define THUMB_SIZE 10
#define EFFECTIVE_THUMB_SIZE 20
@implementation MySlider
-(bool) pointInside:(CGPoint)point withEvent:(UIEvent*)event {
	NSLog (@"pointInside");
	CGRect bounds = self.bounds;
	bounds = CGRectInset(bounds, -10, -8);
	return CGRectContainsPoint(bounds, point);
}

- (bool) beginTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event {
	NSLog (@"beginrackingWithTouch");
	CGRect bounds = self.bounds;
	float thumbPercent = (self.value - self.minimumValue) / (self.maximumValue - self.minimumValue);
	float thumbPos = THUMB_SIZE + (thumbPercent * (bounds.size.width - (2*THUMB_SIZE)));
	CGPoint touchPoint = [touch locationInView:self];
	return (touchPoint.x >= (thumbPos - EFFECTIVE_THUMB_SIZE) && touchPoint.x <= (thumbPos + EFFECTIVE_THUMB_SIZE));
}
@end

MyViewController.m

Code:
#import "MySlider.h"
#import "MyViewController.h"
@implementation MyViewController
@synthesize MysliderCal;
- (IBAction)MysliderCal:(id)sender {
	MySlider *slider = (MySlider *)sender;
	int progressAsInt = (int)(slider.value + 0.5f);
//
//Rest of my code goes in here
//
}

MyViewController.h

Code:
#import <UIKit/UIKit.h>
#define kFilename @"data.plist"
@interface MyViewController : UIViewController <UIActionSheetDelegate> {
	UISlider *MysliderCal;
}
@property (nonatomic, retain) IBOutlet UISlider *MysliderCal;
- (IBAction)MysliderCal:(id)sender;
@end
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
IB is Interface Builder. Does your slider come from a nib or do you create it in code? If you create it in a nib then you need to set the class of the slider to MySlider. If not you are creating a UISlider and the MySlider code isn't used.

The link that describes this code says:

To use the code below, use the Interface Builder to drop a slider on the screen and then change its class from UISlider to MySlider.
 

mpatric

macrumors newbie
Oct 20, 2008
21
0
MTShipp - it's not clear to me what you're trying to do in your code. All you need to do is use the Interface Builder (IB) to drop a standard slider on the screen and then change the class type..

Having looked quickly at your code, you might want to try change MysliderCal in MyViewController from a UISlider to MySlider. Of course that won't fix the problem if you're newing up a UISlider (or you used IB and have not changed the class type).
 

MTShipp

macrumors 6502a
Original poster
Mar 25, 2009
826
183
Raleigh, North Carolina
Thanks all. Yes, I am using the NIB to drop a slider. I did not change the class (that I know of). As stated before, I am very new at this and this is my first app.

I will try to figure out how to change the class and give it another go. I'll post here if successful or not.

Thanks again!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.