带方角的UISegmentedControl [英] UISegmentedControl with square corners

查看:96
本文介绍了带方角的UISegmentedControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用子类修改UISegmentedControl来删除圆角。我似乎无法设置cornerRadius。使SegmentedControl比屏幕更宽(因此从角落切掉)不是一种选择,因为我有4或5个段,然后它们的大小会有所不同。

I would like to modify UISegmentedControl with a subclass to remove the rounded corners. I can't seem to set the cornerRadius. Making the SegmentedControl wider than the screen (and therefor "chop" off the corners) is not an option since I have 4 or 5 segments and they would then vary in size.

有没有办法做到这一点?

Is there a way to do this?

谢谢

推荐答案

您可以设置段的宽度(使用 setWidth:forSegmentAtIndex:)这样您就可以轻松地使左右端段更大(比其他人说的大10倍,然后你可以从任何一端裁掉10px并有方角。您不必将其放大到屏幕宽度,而是将其放在UIView中并用它来裁剪末端。

You can set the width of the segments (using setWidth:forSegmentAtIndex:) so you can easily make the left and right end segments larger (say 10px larger) than the others and then you can crop off 10px from either end and have square corners. You don't have to make it larger than the screen width, instead put it inside a UIView and use it to crop the ends.

另一方面,只是可能只是使用UIControl中的一组自定义UIButton进行自己的分段控制。

On the other hand just could just make your own segmented control using a set of custom UIButtons inside a UIControl.

这篇关于带方角的UISegmentedControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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