eliotfowler / EFCircularSlider

An extensible circular slider for iOS applications
http://eliotfowler.github.io/EFCircularSlider/
MIT License
998 stars 161 forks source link

Value on the circle move #10

Closed vdeleon closed 10 years ago

vdeleon commented 10 years ago

Your EFCircularSlider it just amazing and the cuztomization with my needs are so easy to use i want to make than in the circle is move arounde the big circle in the circle that moves around to show the value instead on a label, i have some issue trying to implement this featured. How you mind helping me with this issue???

eliotfowler commented 10 years ago

I am a little confused. You want the label that shows the current value to be inside the handle that is moving around the circle?

vdeleon commented 10 years ago

Yes, i am asking for that the label that shows the current value to be inside the handle moving around the circle. I having trouble trying to implement that.

tomredman commented 10 years ago

@vdeleon, a quick and dirty way is to expose a handleCenter property on the slider:

 // EFCircularSlider.h
@property (nonatomic) CGPoint handleCenter;

Update at the bottom of drawHandle::

 // EFCircularSlider.m
-(void) drawHandle:(CGContextRef)ctx{

    ...

    self.handleCenter = handleCenter;
}

Then create a label and set its center equal to the handleCenter in hourDidChange: (using the time picker example for this):

// EFTimePickerViewController.m
- (void)viewDidLoad
{
    ...

    //... end of ViewDidLoad:

    handleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 25)];
    handleLabel.textColor = [UIColor redColor];
    handleLabel.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.8];
    handleLabel.layer.cornerRadius = 5.0;
    handleLabel.textAlignment = NSTextAlignmentCenter;
    handleLabel.center = hourSlider.handleCenter;
    [hourSlider addSubview:handleLabel];
}

-(void)hourDidChange:(EFCircularSlider*)slider {
    int newVal = (int)slider.currentValue ? (int)slider.currentValue : 12;
    NSString* oldTime = _timeLabel.text;
    NSRange colonRange = [oldTime rangeOfString:@":"];
    _timeLabel.text = [NSString stringWithFormat:@"%d:%@", newVal, [oldTime substringFromIndex:colonRange.location + 1]];

    handleLabel.center = hourSlider.handleCenter;
    handleLabel.text = _timeLabel.text;
}

And you'll get something like this: ios simulator screen shot 2014-02-24 11 36 46 am

Hope this helps!

eliotfowler commented 10 years ago

@tomredman Great answer, thanks!