Custom Button frame doesn#39;t look as good as Round Rect UIButton(自定义按钮框架看起来不如圆形矩形 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自定义按钮框架看起来不如圆形矩形 UIButton


基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01