带有徽章编号的 UISegmentedControl

发布于 2024-09-30 02:47:07 字数 244 浏览 6 评论 0原文

就像标签栏一样,我想在 UISegmentedControl 上显示徽章。因为我看不到 UISegmentedControl 的任何预定义方法,就像可用于 UITabBar 的方法一样。

alt text

我考虑过将徽章作为图像添加到其顶部,但也许有更好的方法。

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.

alt text

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

檐上三寸雪 2024-10-07 02:47:07

这里是我用来在各种事物上绘制徽章的一个小型第三方库。非常漂亮。例如,更改徽章的颜色以匹配我的设计是微不足道的。

将此类引入项目并将其包含到视图控制器中后,您可以:

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

...然后添加 customBadge1 作为您要标记的任何内容的子视图。

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.

追星践月 2024-10-07 02:47:07

我今天遇到了这个问题,所以我整理了一个 UISegmentedControl 子类,它允许您轻松地在每个段上设置徽章编号。

使用它非常简单:

[segmentedControl setBadgeNumber:1 forSegmentAtIndex:0];

屏幕截图、文档和源代码位于 https://github.com/dave-thompson /MESegmentedControl

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 .

送你一个梦 2024-10-07 02:47:07

与选项卡栏不同,没有徽章属性或方法。如果您想这样做,您只需在其上放置一个自定义图像即可。您可以对分段控件进行子类化并创建一个函数来为您执行此操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文