Make any UIView a full fledged notification center

Related tags

UI RKNotificationHub
Overview

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
Comments
  • Unit tests, Travis CI and Coveralls integration

    Unit tests, Travis CI and Coveralls integration

    Added tests for all public methods of RKNotificationHub using Specta/Expecta, FBSnapshots and Expecta+Snapshots during CocoaPods Test Jam. Currently Travis CI and Coveralls integration uses my GitHub account. Feel free to turn them on yourself as I don't have admin rights on the original repo. See https://travis-ci.org and https://coveralls.io.

    Current coverage is 88%. Note that - (CGRect)nextRectWithDiameter:(float)diameter method is not covered since it's not used anywhere (please review this). Demo ViewController class is also not covered and it's included in stats since it's located in the same folder as RKNotificationHub.m.

    opened by filwag 15
  • UIBarButtonItem item support

    UIBarButtonItem item support

    Since the UIBarButtonItem (in opposite to UITabBarItem) does not have a badge count I am proposing this addition to your framework: A convenience initialiser for a UIBarButtonItem.

    It is actually not a big deal but it took me several hours figuring out how to get the view without loosing build in functionality (like the ability to recognise taps). On top of that I am manipulating the size and position of the badge to fit the bar icon (Feel free to modify this if you don't like my values)

    I was considering to change the font of the counter a little bit (because it is getting fairly small), but that would require some more changes.

    Let me know what you think (especially since I am not really an Objective-C programmer, feel free to correct my style)

    My second commit is adding a Navigation Controller to your example, so you can see what I did. When pressing the icon in the tab bar it should increment the counter animated.

    opened by steilerDev 11
  • Change count to NSUInteger, make local constants static const

    Change count to NSUInteger, make local constants static const

    This makes count an @property of type NSUInteger, which is a more typical Objective-C type. This precludes negative values for count, so the decrement method was modified accordingly. This also makes most of the internal constants static so that they don't enter the global linker namespace and const so that the compiler knows they are constants. The default diameter is exported, made const, and prefixed to avoid naming collisions.

    opened by vokal-isaac 8
  • Setting count = 0 doesn't remove the hub

    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?

    opened by hashmapped 7
  • Lowering OS minimum requirement version

    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?

    opened by imkevinxu 7
  • iOS 6 Compatibility

    iOS 6 Compatibility

    Fixed the display issue that the label's default white background will cover the whole red circle. Changed the s.platform to 6.0 since it is working on iOS 6. In this way this library can be integrated to those project with 6.0 deployment target using CocoaPods.

    opened by powerqian 5
  • Added option to place circle in any corner of the view

    Added option to place circle in any corner of the view

    Happy New Year! :tada: :sheep:

    I was looking for this option but it wasn't implemented yet. This is my first pull request ever, and I am quite new to Objective-C so please don't hesitate to comment or guide me in the right direction.

    opened by uncoverd 5
  • Cannot change the notification's font

    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)

    opened by r-shayestehpour 4
  • Badge disapeare

    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

    opened by petaren 3
  • Indeterminate Badges

    Indeterminate Badges

    I would love an option where the badge is just a red circle no matter what number the count is (as long as it's > 0)

    It's a trend in Chinese apps coined the "Indeterminate Badge" in this article http://dangrover.com/blog/2014/12/01/chinese-mobile-app-ui-trends.html#badges

    I just thought it was interesting and would greatly enhance the use cases of this plugin! Thanks again!

    opened by imkevinxu 3
  • How to change the notification view?

    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?

    opened by demiculus 2
  • kCountMagnitudeAdaptationRatio

    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;

    opened by fantasticiOS 0
  • Not showing on pushview

    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()`**
    
    opened by mengheangrat 1
Releases(2.0.5)
Owner
Richard Kim
Richard Kim
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

patrick piemonte 600 Nov 24, 2022
📹 Framework to Play a Video in the Background of any UIView

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login

Wilson Ding 334 Jan 7, 2023
iOS 11 Control Center Slider

SectionedSlider Control Center Slider Requirements Installation Usage License Requirements iOS 8.0+ Swift 3.0+ Xcode 8.0+ Installation CocoaPods Cocoa

Leonardo Cardoso 361 Dec 3, 2022
Full configurable spreadsheet view user interfaces for iOS applications. With this framework, you can easily create complex layouts like schedule, gantt chart or timetable as if you are using Excel.

kishikawakatsumi/SpreadsheetView has moved! It is being actively maintained at bannzai/SpreadsheetView. This fork was created when the project was mov

Kishikawa Katsumi 34 Sep 26, 2022
Simple battery shaped UIView

BatteryView Simple battery shaped UIView. Usage let batteryView = BatteryView(frame: smallRect) batteryView.level = 42 // anywhere in 0...100 batteryV

Yonat Sharon 50 Sep 19, 2022
UIView and CGRect extension that adds properties to manipulate them efficiently

Geometry Geometry is a UIView and CGRect extension that lets you work with view and rect geometry easier. It adds the following properties to UIView:

Tuomas Artman 92 Sep 7, 2022
An iOS Library that makes shadows management easy on UIView.

ShadowView is an iOS Shadow library that makes view's shadow implementation easy and sweet ?? ?? . Add simple shadows to add a gaussian blurred projec

Pierre 404 Dec 8, 2022
High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton, Promise and more.

SwiftyUI High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton and more. Features SwiftyView GPU rendering Image and Color

Haoking 336 Nov 26, 2022
Custom Beautiful UIView For Handling IDs in iOS

IDView Custom Beautiful UIView For Handling IDs in iOS Setup Set the placeholder images for the front and back faces. override func viewDidLoad()

Omar Labib 6 Aug 21, 2021
A framework which helps you attach observers to `UIView`s to get updates on its frame changes

FrameObserver is a framework that lets you attach observers to any UIView subclass and get notified when its size changes. It doesn't use any Method S

null 11 Jul 25, 2022
Easily use UIKit views in your SwiftUI applications. Create Xcode Previews for UIView elements

SwiftUIKitView Easily use UIKit views in SwiftUI. Convert UIView to SwiftUI View Create Xcode Previews from UIView elements SwiftUI functional updatin

Antoine van der Lee 682 Dec 29, 2022
A swift PropertyWrapper to provide automatic NSView/UIView invalidation when the properties value changes.

A swift PropertyWrapper to provide automatic NSView/UIView invalidation when the properties value changes. It duplicates the @Invalidating propertyWrapper for build targets prior to macOS 12 and iOS 15.

Darren Ford 8 Oct 15, 2021
Easily add drop shadows, borders, and round corners to a UIView.

Easily add drop shadows, borders, rounded corners to a UIView. Installation CocoaPods Add the follwing to your Podfile: pod 'Shades' Usage Storyboard

Aaron Sutton 14 Jun 20, 2020
Anchorage - Single file UIView drag and drop system

anchorage Single file UIView drag and drop system anchors.mp4 License Copyright

● ●●   ● 3 Jan 28, 2022
Make ComposableArchitecture work with UIKit

ComposableUIKit The ComposableArchitecture (TCA) library provides a way of structuring Swift code with the Redux-pattern. It is highly optimized for S

Manuel Maly 11 Nov 5, 2022
AGCircularPicker is helpful component for creating a controller aimed to manage any calculated parameter

We are pleased to offer you our new free lightweight plugin named AGCircularPicker. AGCircularPicker is helpful for creating a controller aimed to man

Agilie Team 617 Dec 19, 2022
A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

Putra Z. 43 Feb 4, 2022
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.

LoadingShimmer An easy way to add a shimmering effect to any view with just single line of code. It is useful as an unobtrusive loading indicator. Thi

Jogendra 1.4k Jan 4, 2023
Create SwiftUI Views with any data

Create SwiftUI Views with any data

Zach Eriksen 20 Jun 27, 2022