iOS中的EFCircularSlider

时间:2017-05-26 05:59:27

标签: ios objective-c circular-slider

我正在使用EFCircularSlider显示圆形滑块。

这是我的代码

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

现在圆圈正常,我想让圆圈的中间空间充当UIButton。我们怎样才能在中间添加按钮? Anyhelp赞赏。提前谢谢。

2 个答案:

答案 0 :(得分:5)

您可以在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];

答案 1 :(得分:0)

你可以做点什么,

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

这是您可以根据需要自定义尺寸的示例!

参考: eliotfowler/EFCircularSlider