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?
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
Not sure if overriding trackRectForBounds will do what you want. You could try this approach:
http://mpatric.blogspot.com/2009/04/more-responsive-sliders-on-iphone.html
#import <UIKit/UIKit.h>
@interface MySlider : UISlider {
}
@end
#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
#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
//
}
#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
I don't know what IB means. Are you saying that I can not use the built in slider in XCode and I must create one manually? If so, I do not know how yet.I assume you are creating the slider in IB. Did you set the type of the slider to MySlider?
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.