Search code examples
iosobjective-ccircular-slider

EFCircularSlider in iOS


I'm using EFCircularSlider to display circular slider.

Here's my code

EFCircularSlider *circularSlider = [[EFCircularSlider alloc] initWithFrame:CGRectMake(0, 0, _myView.frame.size.width, _myView.frame.size.height)];

[circularSlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];

circularSlider.lineWidth = 50;
[self.sliderView addSubview:circularSlider];

Right now the circle is coming properly and I want to make the middle space of the circle to act as a UIButton. How can we add button in the middle? Anyhelp appreciated. Thanks in advance.


Solution

  • You can add button in center of circularSlider.

    CGRect sliderFrame = CGRectMake(60, 150, 200, 200);
    EFCircularSlider* circularSlider = [[EFCircularSlider alloc] initWithFrame:sliderFrame];
    circularSlider.lineWidth = 50;
    [self.view addSubview:circularSlider];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(sliderFrame.origin.x + 50, sliderFrame.origin.y + 50, 100, 100);
    btn.layer.cornerRadius = 50.0;
    btn.backgroundColor = [UIColor greenColor];
    [btn addTarget:self action:@selector(btn_tap:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];