Make sliders larger?

Discussion in 'iOS Programming' started by MTShipp, Jun 9, 2009.

  1. MTShipp macrumors 6502a

    Joined:
    Mar 25, 2009
    Location:
    Raleigh, North Carolina
    #1
    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?
     
  2. justfred macrumors newbie

    Joined:
    May 8, 2009
    #2
    after a quick search:

    http://developer.apple.com/iphone/l...le_ref/occ/instm/UISlider/trackRectForBounds:
     
  3. mpatric macrumors newbie

    Joined:
    Oct 20, 2008
    #3
  4. MTShipp thread starter macrumors 6502a

    Joined:
    Mar 25, 2009
    Location:
    Raleigh, North Carolina
  5. justfred macrumors newbie

    Joined:
    May 8, 2009
    #5
  6. MTShipp thread starter macrumors 6502a

    Joined:
    Mar 25, 2009
    Location:
    Raleigh, North Carolina
    #6
    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.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Your IBAction is the same name as your class?

    P.S. Use CODE tags to enclose your code snippets.
     
  8. MTShipp thread starter macrumors 6502a

    Joined:
    Mar 25, 2009
    Location:
    Raleigh, North Carolina
    #8
    Sorry about the {code} thing. Also, I corrected that mistake but still can not get it to work.
     
  9. MTShipp thread starter macrumors 6502a

    Joined:
    Mar 25, 2009
    Location:
    Raleigh, North Carolina
    #9
    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
    
     
  10. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #10
    I assume you are creating the slider in IB. Did you set the type of the slider to MySlider?
     
  11. MTShipp thread starter macrumors 6502a

    Joined:
    Mar 25, 2009
    Location:
    Raleigh, North Carolina
    #11
    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.
     
  12. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #12
    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:

     
  13. mpatric macrumors newbie

    Joined:
    Oct 20, 2008
    #13
    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).
     
  14. MTShipp thread starter macrumors 6502a

    Joined:
    Mar 25, 2009
    Location:
    Raleigh, North Carolina
    #14
    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!
     

Share This Page