1

我正在使用 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。我们如何在中间添加按钮?任何帮助表示赞赏。提前致谢。

4

2 回答 2

5

您可以在圆形滑块的中心添加按钮。

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];
于 2017-05-26T06:15:24.500 回答
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

于 2017-05-26T06:31:10.727 回答