UISegmentedControl with badge number

房东的猫 提交于 2019-12-21 02:02:09

问题


Just like the tabbar, I want to show badge on UISegmentedControl. As I cant see any predefined methods for UISegmentedControl just like available for UITabBar.

I thought about adding the badge as an image just on top of it, but maybe there is some better way.


回答1:


Here is a little third party library I've used to draw badges on various things. It's pretty nice. For example, changing the color of the badge to match my design was trivial.

Once you bring this class into your project and include it into your view controller, you go:

CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"Badge 1"];

...and then add customBadge1 as a subview of whatever thing you're badging.




回答2:


I had this problem today, so I've put together a UISegmentedControl subclass which allows you to easily set badge numbers on each of the segments.

Using it's as easy as:

[segmentedControl setBadgeNumber:1 forSegmentAtIndex:0];

Screenshot, documentation and source code are at https://github.com/dave-thompson/MESegmentedControl .




回答3:


There is no badge property or method - unlike the tab bar. If you want to do this you will just have to put a custom image over it. You could subclass the segmented control and create a function that does this for you.



来源:https://stackoverflow.com/questions/4077140/uisegmentedcontrol-with-badge-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!