iOS:ui按钮在iOS中绘制圆边框
我需要在按钮外面画一个圆形的边框。下面是附加图像和代码。我还需要显示按钮下面的文本。下面的代码将在下面添加图像和文本。但我怎么能有图层呢iOS:ui按钮在iOS中绘制圆边框,ios,objective-c,iphone,uibutton,Ios,Objective C,Iphone,Uibutton,我需要在按钮外面画一个圆形的边框。下面是附加图像和代码。我还需要显示按钮下面的文本。下面的代码将在下面添加图像和文本。但我怎么能有图层呢 设置按钮宽度和高度ex:width=100和height=100,如果您想要一个圆形,则应相同 imageButton.layer.cornerRadius = 50 // this value should be half from width or height (width = height) imageButton.layer.masksToBound
设置按钮宽度和高度ex:width=100和height=100,如果您想要一个圆形,则应相同
imageButton.layer.cornerRadius = 50 // this value should be half from width or height (width = height)
imageButton.layer.masksToBounds = YES
//如果你想在上面加上边框
imageButton.layer.borderWidth = 1;
imageButton.layer.borderColor = [[UIColor blackColor] CGColor];
你可以这样做
borderView = UIView()
yourButton = UIButton()
borderView.frame.size.width = yourButton.frame.size.width + 1
borderView.layer.cornerRadius = borderView.frame.size.width/2
borderView.clipToBounds = true
borderView.backgroundColor = UIColor.clearColor()
borderView.layer.borderWidth = 1
borderView.layer.borderColor = UIColor.blueColor()
这将不起作用,因为我将获得循环格式的图像之前,我已经添加了该图像下面的文本。现在主要关注的是在图像外部添加颜色,就像在边框中绘制的一样。此边框颜色不起作用。这将生成360°轮廓,而不是像在图像中那样的180°在您的情况下,您可以使用
uiview
-->然后在视图内部(uiimageview和uilabel
)-->,然后unbutton
@Dopapp是绝对正确,我们如何处理此问题,因为在uibutton下面添加文本之后,它提供360°边框颜色为什么不能将图像与边框一起使用?教程的一部分可能会有所帮助。查看CAShapeLayer和+[UIBezierPath bezierPathWithArcCenter:radius:StartTangle:endAngle:顺时针:
borderView = UIView()
yourButton = UIButton()
borderView.frame.size.width = yourButton.frame.size.width + 1
borderView.layer.cornerRadius = borderView.frame.size.width/2
borderView.clipToBounds = true
borderView.backgroundColor = UIColor.clearColor()
borderView.layer.borderWidth = 1
borderView.layer.borderColor = UIColor.blueColor()