ios - CustomBadge 在角标(Badge)周围渲染 "grabage"

标签 ios ios6

我正在使用此问题中讨论的 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];

我得到了我所期待的:

CustomBadge

我正在使用导航 Controller 。当我进入另一个 ViewController 并返回时,我的角标(Badge)出现一条“尾部”:

Bad CustomBadge

如果我去掉了 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/

相关文章:

ios - 如何更快地截取 UIView 屏幕截图?

ios5 - UITableViewCell 的差异 willMoveToSuperview : behavior between iOS 5 and iOS 6

ios - 印象笔记 session authenticateWithViewController :completionHandler: does not trigger completionHandler

ios - 如何将 NSData 写入 Swift 中的新文件?

ios - 这个 SpriteKit 设置中的坐标系有什么问题?

ios - AVAssetExportSession exportAsynchronouslyWithCompletionHandler : method Not Called

iphone - 将地理坐标转换为CGPoint并在UIView中画线

iphone - 如何将 'Maps' 应用程序链接添加到我的每个 map 注释

ios - 检测到 iOS 下 Delphi 的应用被停用

ios - 如何在同一 View 中重新加载 iPhone 中 UITableView 中的数据