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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)