EFCircularSlider in iOS



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

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

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

做这样的事情,

  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

相关内容

  • 没有找到相关文章

最新更新