Latest 1.0.3
Homepage https://github.com/squidyu812/SYBadgeButton
License MIT
Platforms ios 8.0
Authors

SYBadgeButton can customize badge button that you want.

Features

  • [x] It can be implemented in storyboard.
  • [x] Easy to use, highly customizable.
  • [x] All positions are supportable.

Screenshots

SYBadgeButton

Requirements

  • iOS 8.0+
  • Swift 4

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate SYBadgeButton into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'SYBadgeButton'
end

Then, run the following command:

$ pod install

Usage

Code-less Storyboard Implementation

First, add custom class that is SYBadgeButton to your button:

SYBadgeButton

And you can see customized properties in attributes inspector:

SYBadgeButton

Code Implementation

First:

import SYBadgeButton

Then, initialize your button:

let rect = CGRect(x: 20, y: 20, width: 100, height: 50)
let badgeButton = SYBadgeButton(frame: rect)
badgeButton.setTitle("button", for: .normal)
badgeButton.setTitleColor(UIColor.black, for: .normal)
view.addSubview(badgeButton)

Add your badge Value:

badgeButton.badgeValue = "20"

Customize badge color:

badgeButton.badgeBackgroundColor = UIColor.brown
badgeButton.badgeTextColor = UIColor.white

Have several of positions:

// This is topLeft position, and default is topRight position by 0
badgeButton.badgePositionIndex = 1

Also you can use badge offset and edge inset:

// Custom offset and edge inset
badgeButton.badgeOffset = CGPoint(x: 3, y: 3)
badgeButton.leftEdgeInset = 10
badgeButton.rightEdgeInset = 10
badgeButton.topEdgeInset = 5
badgeButton.bottomEdgeInset = 5

Licence

SYBadgeButton is available under the MIT license. See the MIT License for more info.

Latest podspec

{
    "name": "SYBadgeButton",
    "version": "1.0.3",
    "summary": "iOS badge button written in Swift.",
    "description": "SYBadgeButton can customize badge button that you want.",
    "homepage": "https://github.com/squidyu812/SYBadgeButton",
    "license": "MIT",
    "authors": {
        "Squid": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.0",
    "source": {
        "git": "https://github.com/squidyu812/SYBadgeButton.git",
        "tag": "1.0.3"
    },
    "source_files": "Classes/*"
}

Pin It on Pinterest

Share This