Git Product home page Git Product logo

custombadge's Introduction

CustomBadge

About

CustomBadge is a little simple iOS class to draw badges on any iOS view. I'm sure you've seen badges before! For example on App icons when you received a notification. Anyway, there was never an official class or API from Apple to provide those badges inside an App. For instance to put it on top of a Button.

In 2011 I decided to make this class (based on the QuarzCore-Framework). The latest version has reusable badge-styles according to the old iOS design (< iOS 7) and for the current iOS version (8+). But you can compose any style you like with font color, background color, font style, frame, shadow, shinging, ...

Example

custombadge's People

Contributors

ckteebe avatar jtmilne avatar serjg avatar toddmarshall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

custombadge's Issues

CustomBadge crashes when used in FXBlurView

i get this error when used with FXBlurView in iOS 7

Assertion failed: (CGFloatIsValid(x) && CGFloatIsValid(y)), function void CGPathAddArc(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat, bool), file Paths/CGPath.cc, line 279.

so i added the following condition in drawRoundedWithContext
if(rect.size.width > 0 && rect.size.height > 0) {
}

only then we allow the code to be executed else the app will crash

<Error>: CGContextSetStrokeColorWithColor: invalid context 0x0

When the badge is draw a lot of error at diferents methods that say "invalid context 0x0" happend:

: CGContextSaveGState: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextSetAlpha: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextBeginTransparencyLayerWithRect: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextSaveGState: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextSetFillColorWithColor: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextMoveToPoint: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextClosePath: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextDrawPath: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextRestoreGState: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextSaveGState: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextSetStrokeColorWithColor: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextSetLineWidth: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextMoveToPoint: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextAddArc: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextClosePath: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextDrawPath: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextRestoreGState: invalid context 0x0
Jan 14 13:44:26 ??[1765] : CGContextEndTransparencyLayer: invalid context 0x0

Some info at http://stackoverflow.com/questions/3571053/cgcontext-cgbitmapcontextcreateimage-errors-how-to-fix

Badge shadow is being cut off

I ensured that the view was not set to clip to bounds, however the shadow is getting clipped. In all of your screenshots and others also. What can be done to ensure that the shadow is able to be feathered out without the harsh line of where the frame ends?

Please add semantic version tags

Issue title

Please add semantic version tags.

Issue description

I’ve recently added CustomBadge to the CocoaPods package manager repo.

CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.

However, CustomBadge doesn't have any version tags. I’ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.

Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.

In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:

$ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags

Thanks!

Crashed: com.apple.main-thread

CoreGraphics
CG::Path::Subpath::add_arc(CGPoint const&, double, double, double, bool, CGAffineTransform const*)

CustomBadge.m line 136
-[CustomBadge drawRoundedRectWithContext:withRect:]

CustomBadge.m line 233

Crashed: com.apple.main-thread
SIGABRT ABORT at 0x0000000196c47270

Seems something wrong here, my env is iOS8

using CustomBadge from XIB

I have a UIView in XIB, I just set it's file owner to CustomBadge. I have the IBOutlet of this CustomBadge view. My issue is that I am not able to set the badge number on this view now.

CustomBadge how to clear shadows

badge_cart = [CustomBadge customBadgeWithString:[NSString stringWithFormat:@"%d",countValue] withStringColor:[UIColor whiteColor] withInsetColor:[UIColor redColor] withBadgeFrame:NO withBadgeFrameColor:[UIColor clearColor] withScale:0.8 withShining:NO withFrame:CGRectMake(15, -10, 10, 10)];
badge_cart.tag = 10;
[badge_cart.layer setShadowColor:[UIColor clearColor].CGColor];
[badge_cart setBackgroundColor:[UIColor clearColor]];
[Btn_Cart addSubview:badge_cart];

button added on cart there is a small shadow created by custom badge when look very closely to it
i want to remove the shadow which created by CustomBadge view.
For Information please find the below image.
custombatchissue

Will crash on iOS 3

This code uses selectors not present in iOS 3.x. For example,

self.contentScaleFactor = [[UIScreen mainScreen] scale];

both contentScaleFactor and scale properties are not present in iOS 3.x.

If you use it on iOS 3.x it will crash with unrecognized selector

crashes when using from IB

initWithFrame: and initWithCoder methods are not implemented in the CusomBadge class which causes crash, because badgeStyle is nil in these cases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.