自定义按钮框架看起来不如Round Rect UIButton [英] Custom Button frame doesn't look as good as Round Rect UIButton

查看:107
本文介绍了自定义按钮框架看起来不如Round Rect UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按如下方式绘制自定义按钮框:

I'm trying to draw a custom button frame as follows:

UIBezierPath *stroke = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                  cornerRadius:RECT_CORNECR_RADIUS];

[stroke stroke];

但由于某些原因,角落曲线看起来比侧面更有思想。如果你看看UIButton的默认框架,它是非常统一的。 A是UIButton,B是自定义按钮。

But for some reason the corner curves look thinker than the sides. If you look at the UIButton's default frame it's very uniform. A is a UIButton, B is a custom button.

任何想法如何让它更像UIButton。

Any ideas how I can make it more like the UIButton.

推荐答案

您正在抚摸按钮的边界。这将绘制您的线在视图边缘的中心,因此线的一半厚度超出边界并且不绘制。这就是它在角落里的全厚度的原因。在你的边界矩形上使用 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.

这篇关于自定义按钮框架看起来不如Round Rect UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆