EFCircularSlider in iOS

166 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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];
2
On

You can do something like,

  CGRect sliderFrame = CGRectMake(60, 150, 200, 200);
EFCircularSlider* circularSlider = [[EFCircularSlider alloc] initWithFrame:sliderFrame];
[circularSlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:circularSlider];
[circularSlider setCurrentValue:10.0f];

UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(25, 25, 150, 150)];
[button setBackgroundColor:[UIColor orangeColor]];
button.layer.cornerRadius = 75;
[button setTitle:@"Tap here" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

[circularSlider addSubview:button];

This is example you can customize size according to your need!

Reference : eliotfowler/EFCircularSlider