且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自定义按钮框架看起来不如圆形矩形 UIButton

更新时间:2023-12-04 07:57:52

您正在抚摸按钮的边界.这会将您的线绘制在视图边缘的中心,因此线的一半粗细在边界之外并且不会被绘制.这就是为什么它在角落里是全厚度的.在边界矩形上使用 CGRectInset (插入线条厚度的一半)并描边那个矩形.

You are stroking the bounds of your button. This will draw your line centred over the edge the view, so half of the thickness of the line is outside the bounds and is not drawn. This is why it is full thickness in the corners. Use CGRectInset on your bounds rectangle (inset by half the thickness of your line) and stroke THAT rect.