View Full Version : Make sliders larger?
MTShipp
Jun 9, 2009, 02:37 PM
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
Jun 9, 2009, 05:24 PM
after a quick search:
trackRectForBounds:
Returns the drawing rectangle for the slider’s track.
- (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/library/documentation/UIKit/Reference/UISlider_Class/Reference/Reference.html#//apple_ref/occ/instm/UISlider/trackRectForBounds:
mpatric
Jun 10, 2009, 04:38 AM
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
MTShipp
Jun 10, 2009, 09:54 AM
Thanks to the both of you! Fantastic!
justfred
Jun 10, 2009, 02:24 PM
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
yes, that does look much better.
MTShipp
Jun 10, 2009, 05:37 PM
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:@"%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.
dejo
Jun 10, 2009, 05:43 PM
Your IBAction is the same name as your class?
P.S. Use CODE tags to enclose your code snippets.
MTShipp
Jun 10, 2009, 07:18 PM
Sorry about the {code} thing. Also, I corrected that mistake but still can not get it to work.
MTShipp
Jun 10, 2009, 07:27 PM
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
#import <UIKit/UIKit.h>
@interface MySlider : UISlider {
}
@end
MySlider.m
#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
#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
#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
Jun 10, 2009, 08:02 PM
I assume you are creating the slider in IB. Did you set the type of the slider to MySlider?
MTShipp
Jun 10, 2009, 08:23 PM
I assume you are creating the slider in IB. Did you set the type of the slider to MySlider?
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.
PhoneyDeveloper
Jun 10, 2009, 09:46 PM
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
Jun 11, 2009, 04:02 AM
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
Jun 11, 2009, 07:01 AM
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!
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.