Git Product home page Git Product logo

rknotificationhub's Introduction

RKNotificationHub

A way to quickly add a notification icon to a UIView (iOS6 and up). Support

demo

Code:

  RKNotificationHub* hub = [[RKNotificationHub alloc]initWithView:yourView]; // sets the count to 0
  [hub increment]; // increments the count to 1, making the notification visible

Pod

    pod 'RKNotificationHub'

USAGE

increment

  [hub increment];
  -(void)increment;
  -(void)incrementBy:(int)amount;
  -(void)decrement;
  -(void)decrementBy:(int)amount;
  @property (nonatomic, assign) int count; //%%% set to a certain number

Combine Actions!

blink

  [hub increment];
  [hub pop];

CUSTOMIZE

blink

  //%%% COLOR
  [hub setCircleColor:[UIColor colorWithRed:0.98 green:0.66 blue:0.2 alpha:1]
           labelColor:[UIColor whiteColor]];

frame

  //%%% CIRCLE FRAME
  [hub setCircleAtFrame:CGRectMake(-10, -10, 30, 30)]; //frame relative to the view you set it to

  //%%% MOVE FRAME
  [hub moveCircleByX:-5 Y:5]; // moves the circle 5 pixels left and down from its current position

  //%%% CIRCLE SIZE
  [hub scaleCircleSizeBy:2]; // doubles the size of the circle, keeps the same center

blank

  //%%% BLANK BADGE
  [hub hideCount];
  /* shoutout to imkevinxu for this suggestion */

TROUBLESHOOTING

Notification isn't showing up!

  • If the hub value is < 1, the circle hides. Try calling [increment]
  • Make sure the view you set the hub to is visible (i.e. did you call [self.view addSubview: yourView]?)
  • Make sure you didn't call [hideCount] anywhere. Call [showCount] to counter this

It isn't incrementing / decrementing properly!

  • I've written it so that any count < 1 doesn't show up. If you need help customizing this, reach out to me

The circle is in a weird place

  • If you want to resize the circle, use [scaleCircleSizeBy:]. 0.5 will give you half the size, 2 will give you double
  • If the circle is just a few pixels off, use [moveCircleByX: Y:]. This shifts the circle by the number of pixels given
  • If you want to manually set the circle, call [setCircleAtFrame:] and give it your own CGRect

Something else isn't working properly

  • Send me a tweet @cwRichardKim with #RKNotificationHub so that other people can search these issues too
  • Use github's issue reporter on the right
  • Send me an email [email protected] (might take a few days)

Updates

  • 1.0.0 first release with cocoapod
  • 1.0.1 cocoapod allows iOS 7.0
  • 1.0.2 added "hideCount", "showCount", and "count" methods, allowing indeterminate badges with no number
  • 1.0.5 added bubble expansion for larger numbers (gif)
  • 2.0.0 changed count to NSUInteger (removed support for negative counts), made local constants static const
  • 2.0.1 iOS 6 compatability
  • 2.0.2 changed count back to 'int' for better swift compatability
  • 2.0.4 fixed cocoapod update issue

Areas for Improvements / involvement

  • A mechanism for adding a custom animation
  • Singleton option

rknotificationhub's People

Contributors

bryant1410 avatar chillpop avatar cwrichardkim avatar esqarrouth avatar filwag avatar petaren avatar redcapua avatar sohailkh avatar steilerdev avatar suriyaakudoisc avatar tunam3lt avatar vokal-isaac 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  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

rknotificationhub's Issues

Badge disapeare

I put the NotificationHub on a UIImageView in a UITableViewCell. When I select that tableviewcell and animate to the detailViewController then the badge disappears and only the number label is visible.
img_0010
img_0011

I found a bug. It makes wrong when I change hub setting order. and I have tried to fix it. It seems that works.

  • (void)moveCircleByX:(CGFloat)x Y:(CGFloat)y
    {
    CGRect frame = redCircle.frame;
    frame.origin.x += x;
    frame.origin.y += y;

    // fix = > if we write hub.count = 999 first, and then execute -moveCircleByX:Y:, after that we execute -increment or do others, cause the method -expandToFitLargerDigits calculate the new frame base on the initialFrame, which is just changed by -moveCircleByX:Y: . It would make wrong newly frame! So we must reset, and let -expandToFitLargerDigits to recalculate.
    frame.size = initialFrame.size ;

    [self setCircleAtFrame:frame];
    }

Cannot change the notification's font

I'm trying to change the font with the following line but the notification's font won't change.
(there is no problem with loading the font, I'm using it elsewhere in the app)
hub.countLabelFont = UIFont(name: "MyFont", size: 8)

CocoaPods latest versions

RKNotificationHub 2.0.2, 2.0.3 and 2.0.4 podspecs are missing on CocoaPods/Specs repo, therefore latest version that gets downloaded is 2.0.1

can we set maxCount

can we set maxCount , when the count > maxCount , it displays just like 99+

Lowering OS minimum requirement version

[!] The platform of the target Pods (iOS 7.0) is not compatible with RKNotificationHub (1.0.0) which has a minimum requirement of iOS 8.1.

Any chance you could look into making this have a min requirement of iOS 7.0? Does it use any 8.1-specific features?

Setting count = 0 doesn't remove the hub

I am using Swift 2.1 and when I set count to 0 after a asynchronous call in completion block, it doesn't remove the red dot, and the count stays the same.
Here is my pseudocode:

// viewWillAppear
let notificationHub = RKNotificationHub(barButtonItem: self.toolBarButtonItem)
if there is an existing count {
    notificationHub.increment()
}
asynchronous completion call block {
    if needs to increment {
        notificationHub.increment()
    } else {
        notificationHub.count = 0
    }
}

So if there wasn't any existing count (line 2), nothing shows so that's good. But if there was an existing count and I try to remove in the completion block, it doesn't remove a hub that existing count created.
Am I doing something wrong here?

Not showing on pushview

` let cartBarButton: UIBarButtonItem = UIBarButtonItem(title: "Test", style: UIBarButtonItemStyle.Plain, target: self, action: nil)//#selector(self.toggleLeft))
let attributes = [NSFontAttributeName: UIFont.fontAwesomeOfSize(25)] as Dictionary!
cartBarButton.setTitleTextAttributes(attributes, forState: .Normal)
cartBarButton.title = String.fontAwesomeIconWithName(.ShoppingCart)
cartBarButton.tintColor = CommonMainColor
self.navigationItem.rightBarButtonItem = cartBarButton

    let hub:RKNotificationHub = RKNotificationHub(barButtonItem: cartBarButton)
    hub.increment()
    hub.count = 90
    hub.setCircleAtFrame(CGRectMake(15, -5, 20, 20))
    **hub.pop()`**

How to change the notification view?

What I want to do is change the red circle to some other image, like a lightbulb.
I tried changing the hubView but it didnt work. When I tried setting the backgroundColor as an image then the image was scaled and it only show a small part of the image.
How can I do it with this library?

kCountMagnitudeAdaptationRatio

We use a view to hold a UILabel,use "setFrame"function to hold a text,but actually,the width we calculated is not precise.kCountMagnitudeAdaptationRatio will not as precise as we expected when count becomes larger and larger.What causes the problem.
CGSize size = [badgeText boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:1|2|8|32 attributes:@{NSFontAttributeName:TT_FONT_ZH(10)} context:nil].size;

Continuous blinking animation

Hi, is it possible to do always blinking animation for the badge? Could you guide me on how to achieve this (I might have overlooked)? I'm using this on a UITableViewCell

outer ring had noise when set border

when I set border color and width
the outer ring had thin circle color border

[hub setCircleColor:[UIColor brownColor] labelColor:[UIColor greenColor]];
[hub setCircleBorderColor:[UIColor yellowColor] borderWidth:2.0];

simulator screen shot - iphone 7 - 2017-09-15 at 11 39 35

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.