我正在使用此问题中讨论的 CustomBadge 库:How can I add a badge to a standard UIButton?
这是我的代码:
CustomBadge* customBadge =
[CustomBadge customBadgeWithString:@"$2.99"
withStringColor:[UIColor whiteColor]
withInsetColor:[UIColor redColor]
withBadgeFrame:YES
withBadgeFrameColor:[UIColor whiteColor]
withScale:1.0
withShining:NO];
customBadge.frame = CGRectMake(self.btnUpgrade.frame.size.width - customBadge.frame.size.width + 15, -15, customBadge.frame.size.width, customBadge.frame.size.height);
[self.btnUpgrade addSubview:customBadge];
我得到了我所期待的:
我正在使用导航 Controller 。当我进入另一个 ViewController 并返回时,我的角标(Badge)出现一条“尾部”:
如果我去掉了 customBadge.frame 行,角标(Badge)就会正确呈现(尽管位置错误)。
代码正在 viewWillAppear 上执行:
知道是什么原因造成的吗?
CustomBadge 代码位于:https://github.com/ckteebe/CustomBadge/blob/master/Classes/CustomBadge.m
最佳答案
我猜问题出在路径上。因此,为了解决这个问题,我会:
- 检查您的路径是否从您想要的点开始,而不是从随机点开始。这意味着您需要在调用
CGContextBeginPath
之前调用CGContextMoveToPoint
- 在使用每个路径之前关闭 (
CGContextClosePath
)。
关于ios - CustomBadge 在角标(Badge)周围渲染 "grabage",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14565304/