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

查看:18
本文介绍了自定义按钮框架看起来不如圆形矩形 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.

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

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