gpt4 book ai didi

iphone - 在 iPhone 中是否有任何标准方法来实现 "blue badge"?

转载 作者:行者123 更新时间:2023-12-03 18:20:17 25 4
gpt4 key购买 nike

许多 iPhone 应用程序使用蓝色徽章来指示 subview 中的项目数量,例如邮件客户端:

iPhoto http://img.skitch.com/20081103-tjr9yupbhgr3sqfh7u56if4rsn.preview.jpg

是否有任何标准方法(甚至 API)可以做到这一点?

更新:我创建了一个名为 BlueBadge 的类来执行此操作。可以通过 http://github.com/leonho/iphone-libs/tree/master 获取。

最佳答案

据我所知,没有可用的 API。然而,使用 CoreGraphics(NSBezierPath 在 iPhone 上不可用),您可以非常轻松地做到这一点。它只是 CGPath 中的两条弧和一些文本:

CGContextRef        context = UIGraphicsGetCurrentContext();
float radius = bounds.size.height / 2.0;
NSString *countString = [NSString stringWithFormat: @"%d", count];

CGContextClearRect(context, bounds);

CGContextSetFillColorWithColor(context, ovalColor);
CGContextBeginPath(context);
CGContextAddArc(context, radius, radius, radius, M_PI / 2 , 3 * M_PI / 2, NO);
CGContextAddArc(context, bounds.size.width - radius, radius, radius, 3 * M_PI / 2, M_PI / 2, NO);
CGContextClosePath(context);
CGContextFillPath(context);

[[UIColor whiteColor] set];

UIFont *font = [UIFont boldSystemFontOfSize: 14];
CGSize numberSize = [countString sizeWithFont: font];

bounds.origin.x = (bounds.size.width - numberSize.width) / 2;

[countString drawInRect: bounds withFont: font];

关于iphone - 在 iPhone 中是否有任何标准方法来实现 "blue badge"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/258375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com