diff --git a/Classes/MIBadgeButton.swift b/Classes/MIBadgeButton.swift
index d8080a5..456751f 100644
--- a/Classes/MIBadgeButton.swift
+++ b/Classes/MIBadgeButton.swift
@@ -8,33 +8,383 @@
import UIKit
-public class MIBadgeButton: UIButton {
+/**
+ Define badge anchor
+ **/
+public enum MIAnchor{
+ case TopLeft(topOffset : CGFloat, leftOffset : CGFloat)
+ case TopRight(topOffset : CGFloat, rightOffset : CGFloat)
+ case BottomLeft(bottomOffset : CGFloat, leftOffset : CGFloat)
+ case BottomRight(bottomOffset : CGFloat, rightOffset : CGFloat)
+ case center
+}
+
+@IBDesignable
+open class MIBadgeButton: UIButton {
- private var badgeLabel: UILabel
- public var badgeString: String? {
+ fileprivate var badgeLabel: UILabel
+
+ @IBInspectable
+ open var badgeString: String? {
didSet {
setupBadgeViewWithString(badgeText: badgeString)
}
}
- public var badgeEdgeInsets: UIEdgeInsets? {
+// @objc
+// open var badgeEdgeInsets: UIEdgeInsets = .zero
+ /**
+ Factor that can change corner radius of badge
+
+ This value will be calculate like:
+ (Badge Label Height) / (this value)
+ **/
+ @IBInspectable
+ open var cornerRadiusFactor : CGFloat = 2{
+
+ didSet{
+ setupBadgeViewWithString(badgeText: badgeString)
+ }
+ }
+
+ /**
+ Vertical margin in badge
+ This is the space between text and badge's vertical edge
+ **/
+ fileprivate var innerVerticalMargin : CGFloat = 5.0{
+
+ didSet{
+ setupBadgeViewWithString(badgeText: badgeString)
+ }
+ }
+
+ /**
+ Horizontal margin in badge
+ This is the space between text and badge's horizontal edge
+ **/
+ fileprivate var innerHorizontalMargin : CGFloat = 10.0{
+
+ didSet{
+ setupBadgeViewWithString(badgeText: badgeString)
+ }
+ }
+
+ /**
+ Vertical margin in badge
+ This is the space between text and badge's vertical edge
+ **/
+ @IBInspectable
+ open var verticalMargin : CGFloat{
+
+ set{
+
+ self.innerVerticalMargin = max(0, newValue)
+ }
+
+ get{
+
+ return innerVerticalMargin
+ }
+ }
+
+ /**
+ Horizontal margin in badge
+ This is the space between text and badge's horizontal edge
+ **/
+ @IBInspectable
+ open var horizontalMargin : CGFloat{
+
+ set{
+ self.innerHorizontalMargin = max(0, newValue)
+ }
+
+ get{
+
+ return innerHorizontalMargin
+ }
+ }
+
+ open var badgeEdgeInsets: UIEdgeInsets? {
didSet {
setupBadgeViewWithString(badgeText: badgeString)
}
}
- public var badgeBackgroundColor = UIColor.redColor() {
+ @IBInspectable
+ open var badgeBackgroundColor : UIColor = UIColor.red {
didSet {
badgeLabel.backgroundColor = badgeBackgroundColor
}
}
- public var badgeTextColor = UIColor.whiteColor() {
+ @IBInspectable
+ open var badgeTextColor : UIColor = UIColor.white {
didSet {
badgeLabel.textColor = badgeTextColor
}
}
+
+ /**
+ Can be adjust from Interface Builder
+ EdgeInsetLeft
+ **/
+ @IBInspectable
+ open var edgeInsetLeft : CGFloat{
+ set{
+ if let edgeInset = badgeEdgeInsets{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: edgeInset.top, left: newValue, bottom: edgeInset.bottom, right: edgeInset.right)
+ }
+ else{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: 0.0, left: newValue, bottom: 0.0, right: 0.0)
+ }
+ }
+ get{
+
+ if let edgeInset = badgeEdgeInsets{
+ return edgeInset.left
+ }
+
+ return 0.0
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ EdgeInsetRight
+ **/
+ @IBInspectable
+ open var edgeInsetRight : CGFloat{
+ set{
+
+ if let edgeInset = badgeEdgeInsets{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: edgeInset.top, left: edgeInset.left, bottom: edgeInset.bottom, right: newValue)
+ }
+ else{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: newValue)
+ }
+ }
+ get{
+
+ if let edgeInset = badgeEdgeInsets{
+ return edgeInset.right
+ }
+
+ return 0.0
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ EdgeInsetTop
+ **/
+ @IBInspectable
+ open var edgeInsetTop : CGFloat{
+ set{
+
+ if let edgeInset = badgeEdgeInsets{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: newValue, left: edgeInset.left, bottom: edgeInset.bottom, right: edgeInset.right)
+ }
+ else{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: newValue, left: 0.0, bottom: 0.0, right: 0.0)
+ }
+ }
+ get{
+
+ if let edgeInset = badgeEdgeInsets{
+ return edgeInset.top
+ }
+
+ return 0.0
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ EdgeInsetBottom
+ **/
+ @IBInspectable
+ open var edgeInsetBottom : CGFloat{
+ set{
+
+ if let edgeInset = badgeEdgeInsets{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: edgeInset.top, left: edgeInset.left, bottom: newValue, right: edgeInset.right)
+ }
+ else{
+
+ self.badgeEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: newValue, right: 0.0)
+ }
+ }
+ get{
+
+ if let edgeInset = badgeEdgeInsets{
+ return edgeInset.bottom
+ }
+
+ return 0.0
+ }
+ }
+
+ /**
+ Badge's anchor. TopLeft, TopRight, BottomLeft, BottomRight and Center
+ Offset is required depend on anchor. Assign 0.0 if don't need offset
+
+ Note: badgeEdgeInsets are taking into count when calculate position
+ **/
+ open var badgeAnchor : MIAnchor = .TopRight(topOffset: 0.0, rightOffset: 0.0){
+ didSet{
+ setupBadgeViewWithString(badgeText: badgeString)
+ }
+ }
+
+ /**
+ AnchorIndex is an Integer value from 0 to 4 each value represent different anchor of badge
+
+ 0 = TopLeft
+
+ 1 = TopRight
+
+ 2 = BottomLeft
+
+ 3 = BottomRight
+
+ 4 = Center
+ **/
+ fileprivate var anchorIndex : Int = 0{
+ didSet{
+
+ switch anchorIndex {
+ case 0:
+ self.badgeAnchor = .TopLeft(topOffset: topOffset, leftOffset: leftOffset)
+ break
+ case 1:
+ self.badgeAnchor = .TopRight(topOffset: topOffset, rightOffset: rightOffset)
+ break
+ case 2:
+ self.badgeAnchor = .BottomLeft(bottomOffset: buttomOffset, leftOffset: leftOffset)
+ break
+ case 3:
+ self.badgeAnchor = .BottomRight(bottomOffset: buttomOffset, rightOffset: rightOffset)
+ break
+ case 4:
+ self.badgeAnchor = .center
+ break
+ default:
+ print("Unknow anchor position. Fallback to default")
+ self.anchorIndex = 1
+ }
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ It represent different anchor on button
+ Values are 0 ~ 4
+
+ 0 = TopLeft
+
+ 1 = TopRight
+
+ 2 = BottomLeft
+
+ 3 = BottomRight
+
+ 4 = Center
+ **/
+ @IBInspectable
+ open var anchor : Int{
+ set{
+
+ self.anchorIndex = min(max(0, newValue), 4)
+ }
+
+ get{
+ return self.anchorIndex
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ Left offset of anchor
+
+ Value is effect when anchor are:
+
+ TopLeft
+
+ BottomLeft
+ **/
+ @IBInspectable
+ open var leftOffset : CGFloat = 0{
+ didSet{
+
+ //get anchor of index and assign to anchorIndex
+ //to trigger view to update
+ let ach = anchor
+ self.anchorIndex = ach
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ Right offset of anchor
+
+ Value is effect when anchor are:
+
+ TopRight
+
+ BottomRight
+ **/
+ @IBInspectable
+ open var rightOffset : CGFloat = 0{
+ didSet{
+ let ach = anchor
+ self.anchorIndex = ach
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ Top offset of anchor
+
+ Value is effect when anchor are:
+
+ TopLeft
+
+ TopRight
+ **/
+ @IBInspectable
+ open var topOffset : CGFloat = 0{
+ didSet{
+ let ach = anchor
+ self.anchorIndex = ach
+ }
+ }
+
+ /**
+ Can be adjust from Interface Builder
+ Bottom offset of anchor
+
+ Value is effect when anchor are:
+
+ BottomLeft
+
+ BottomRight
+ **/
+ @IBInspectable
+ open var buttomOffset : CGFloat = 0{
+ didSet{
+ let ach = anchor
+ self.anchorIndex = ach
+ }
+ }
+
override public init(frame: CGRect) {
badgeLabel = UILabel()
super.init(frame: frame)
@@ -48,19 +398,21 @@ public class MIBadgeButton: UIButton {
setupBadgeViewWithString(badgeText: "")
}
- public func initWithFrame(frame frame: CGRect, withBadgeString badgeString: String, withBadgeInsets badgeInsets: UIEdgeInsets) -> AnyObject {
+ open func initWithFrame(frame: CGRect, withBadgeString badgeString: String, withBadgeInsets badgeInsets: UIEdgeInsets, badgeAnchor : MIAnchor = .TopRight(topOffset: 0.0, rightOffset: 0.0)) -> AnyObject {
badgeLabel = UILabel()
badgeEdgeInsets = badgeInsets
+ self.badgeAnchor = badgeAnchor
setupBadgeViewWithString(badgeText: badgeString)
return self
}
- private func setupBadgeViewWithString(badgeText badgeText: String?) {
+ /*
+ fileprivate func setupBadgeViewWithString(badgeText: String?) {
badgeLabel.clipsToBounds = true
badgeLabel.text = badgeText
- badgeLabel.font = UIFont.systemFontOfSize(12)
- badgeLabel.textAlignment = .Center
+ badgeLabel.font = UIFont.systemFont(ofSize: 12)
+ badgeLabel.textAlignment = .center
badgeLabel.sizeToFit()
let badgeSize = badgeLabel.frame.size
@@ -68,34 +420,108 @@ public class MIBadgeButton: UIButton {
let width = max(height, Double(badgeSize.width) + 10.0)
var vertical: Double?, horizontal: Double?
- if let badgeInset = self.badgeEdgeInsets {
- vertical = Double(badgeInset.top) - Double(badgeInset.bottom)
- horizontal = Double(badgeInset.left) - Double(badgeInset.right)
-
- let x = (Double(bounds.size.width) - 10 + horizontal!)
- let y = -(Double(badgeSize.height) / 2) - 10 + vertical!
- badgeLabel.frame = CGRect(x: x, y: y, width: width, height: height)
+ let badgeInset = self.badgeEdgeInsets
+ vertical = Double(badgeInset.top) - Double(badgeInset.bottom)
+ horizontal = Double(badgeInset.left) - Double(badgeInset.right)
+
+ let x = (Double(bounds.size.width) - 10 + horizontal!)
+ let y = -(Double(badgeSize.height) / 2) - 10 + vertical!
+ badgeLabel.frame = CGRect(x: x, y: y, width: width, height: height)
+
+ setupBadgeStyle()
+ addSubview(badgeLabel)
+
+ if let text = badgeText {
+ badgeLabel.isHidden = text != "" ? false : true
} else {
- let x = CGRectGetWidth(self.frame) - CGFloat((width / 2.0))
- let y = CGFloat(-(height / 2.0))
- badgeLabel.frame = CGRectMake(x, y, CGFloat(width), CGFloat(height))
+ badgeLabel.isHidden = true
}
+ }
+ */
+ fileprivate func setupBadgeViewWithString(badgeText: String?){
+ badgeLabel.clipsToBounds = true
+ badgeLabel.text = badgeText
+ badgeLabel.font = UIFont.systemFont(ofSize: 12)
+ badgeLabel.textAlignment = .center
+ badgeLabel.sizeToFit()
+ let badgeSize = badgeLabel.bounds.size
+
+ let height = max(20, CGFloat(badgeSize.height) + innerVerticalMargin)
+ let width = max(height, CGFloat(badgeSize.width) + innerHorizontalMargin)
+
+ var vertical: CGFloat, horizontal: CGFloat
+ var x : CGFloat = 0, y : CGFloat = 0
+
+ if let badgeInset = self.badgeEdgeInsets{
+
+ vertical = CGFloat(badgeInset.top) - CGFloat(badgeInset.bottom)
+ horizontal = CGFloat(badgeInset.left) - CGFloat(badgeInset.right)
+
+ }
+ else{
+
+ vertical = 0.0
+ horizontal = 0.0
+ }
+
+ //calculate badge X Y position
+ calculateXYForBadge(x: &x, y: &y, badgeSize: CGSize(width: width, height: height))
+
+ //add badgeEdgeInset
+ x = x + horizontal
+ y = y + vertical
+
+ badgeLabel.frame = CGRect(x: x, y: y, width: width, height: height)
+
setupBadgeStyle()
addSubview(badgeLabel)
if let text = badgeText {
- badgeLabel.hidden = text != "" ? false : true
+ badgeLabel.isHidden = text != "" ? false : true
} else {
- badgeLabel.hidden = true
+ badgeLabel.isHidden = true
}
+
+ }
+
+ /**
+ Calculate badge's X Y position.
+ Offset are taking into count
+ **/
+ fileprivate func calculateXYForBadge(x : inout CGFloat, y : inout CGFloat, badgeSize : CGSize){
+ switch self.badgeAnchor {
+
+ case .TopLeft(let topOffset, let leftOffset):
+ x = -badgeSize.width/2 + leftOffset
+ y = -badgeSize.height/2 + topOffset
+ break
+
+ case .TopRight(let topOffset, let rightOffset):
+ x = self.bounds.size.width - badgeSize.width/2 + rightOffset
+ y = -badgeSize.height/2 + topOffset
+ break
+
+ case .BottomLeft(let bottomOffset, let leftOffset):
+ x = -badgeSize.width/2 + leftOffset
+ y = self.bounds.size.height - badgeSize.height/2 + bottomOffset
+ break
+ case .BottomRight(let bottomOffset, let rightOffset):
+ x = self.bounds.size.width - badgeSize.width/2 + rightOffset
+ y = self.bounds.size.height - badgeSize.height/2 + bottomOffset
+ break
+ case .center:
+ x = self.bounds.size.width/2 - badgeSize.width/2
+ y = self.bounds.size.height/2 - badgeSize.height/2
+ break
+ }
}
- private func setupBadgeStyle() {
- badgeLabel.textAlignment = .Center
+ fileprivate func setupBadgeStyle() {
+ badgeLabel.textAlignment = .center
badgeLabel.backgroundColor = badgeBackgroundColor
badgeLabel.textColor = badgeTextColor
- badgeLabel.layer.cornerRadius = badgeLabel.bounds.size.height / 2
+ badgeLabel.layer.cornerRadius = badgeLabel.bounds.size.height / cornerRadiusFactor
}
}
diff --git a/MIBadgeButton-Swift.podspec b/MIBadgeButton-Swift.podspec
index a9e4c54..f3961ad 100644
--- a/MIBadgeButton-Swift.podspec
+++ b/MIBadgeButton-Swift.podspec
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "MIBadgeButton-Swift"
- s.version = "0.4"
+ s.version = "0.5"
s.summary = "iOS custom button badge."
s.homepage = "https://github.com/mustafaibrahim989/MIBadgeButton-Swift"
diff --git a/MIBadgeButton.xcodeproj/project.pbxproj b/MIBadgeButton.xcodeproj/project.pbxproj
index e9b01ee..3819287 100644
--- a/MIBadgeButton.xcodeproj/project.pbxproj
+++ b/MIBadgeButton.xcodeproj/project.pbxproj
@@ -174,14 +174,16 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
- LastUpgradeCheck = 0700;
+ LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Youxel Technology";
TargetAttributes = {
3DCA509619AE63610002F2E6 = {
CreatedOnToolsVersion = 6.0;
+ LastSwiftMigration = 0800;
};
3DCA50A819AE63610002F2E6 = {
CreatedOnToolsVersion = 6.0;
+ LastSwiftMigration = 0800;
TestTargetID = 3DCA509619AE63610002F2E6;
};
};
@@ -279,8 +281,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -289,6 +293,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
@@ -323,8 +328,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -332,6 +339,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -341,6 +349,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
METAL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
@@ -356,6 +365,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.youxel.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
+ SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
@@ -370,6 +380,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.youxel.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
+ SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
@@ -391,6 +402,7 @@
METAL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.youxel.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Debug;
@@ -408,6 +420,7 @@
METAL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.youxel.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Release;
diff --git a/MIBadgeButton.xcodeproj/project.xcworkspace/xcuserdata/mustafai.xcuserdatad/UserInterfaceState.xcuserstate b/MIBadgeButton.xcodeproj/project.xcworkspace/xcuserdata/mustafai.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..03879c9
Binary files /dev/null and b/MIBadgeButton.xcodeproj/project.xcworkspace/xcuserdata/mustafai.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/MIBadgeButton.xcodeproj/xcuserdata/mustafai.xcuserdatad/xcschemes/MIBadgeButton.xcscheme b/MIBadgeButton.xcodeproj/xcuserdata/mustafai.xcuserdatad/xcschemes/MIBadgeButton.xcscheme
new file mode 100644
index 0000000..eebb1f3
--- /dev/null
+++ b/MIBadgeButton.xcodeproj/xcuserdata/mustafai.xcuserdatad/xcschemes/MIBadgeButton.xcscheme
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MIBadgeButton.xcodeproj/xcuserdata/mustafai.xcuserdatad/xcschemes/xcschememanagement.plist b/MIBadgeButton.xcodeproj/xcuserdata/mustafai.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..407c13d
--- /dev/null
+++ b/MIBadgeButton.xcodeproj/xcuserdata/mustafai.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,27 @@
+
+
+
+
+ SchemeUserState
+
+ MIBadgeButton.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 3DCA509619AE63610002F2E6
+
+ primary
+
+
+ 3DCA50A819AE63610002F2E6
+
+ primary
+
+
+
+
+
diff --git a/MIBadgeButton/AppDelegate.swift b/MIBadgeButton/AppDelegate.swift
index 0b4ed8c..48901ee 100644
--- a/MIBadgeButton/AppDelegate.swift
+++ b/MIBadgeButton/AppDelegate.swift
@@ -13,30 +13,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
- func applicationWillResignActive(application: UIApplication) {
+ func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- func applicationDidEnterBackground(application: UIApplication) {
+ func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- func applicationWillEnterForeground(application: UIApplication) {
+ func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- func applicationDidBecomeActive(application: UIApplication) {
+ func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- func applicationWillTerminate(application: UIApplication) {
+ func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
diff --git a/MIBadgeButton/Base.lproj/Main.storyboard b/MIBadgeButton/Base.lproj/Main.storyboard
index 4b7f420..cc38d81 100644
--- a/MIBadgeButton/Base.lproj/Main.storyboard
+++ b/MIBadgeButton/Base.lproj/Main.storyboard
@@ -1,8 +1,12 @@
-
-
+
+
+
+
+
-
+
+
@@ -14,44 +18,65 @@
-
+
-
+
-
+
diff --git a/MIBadgeButton/Images.xcassets/1.imageset/1.png b/MIBadgeButton/Images.xcassets/1.imageset/1.png
index dce1431..1540273 100644
Binary files a/MIBadgeButton/Images.xcassets/1.imageset/1.png and b/MIBadgeButton/Images.xcassets/1.imageset/1.png differ
diff --git a/MIBadgeButton/Images.xcassets/AppIcon.appiconset/Contents.json b/MIBadgeButton/Images.xcassets/AppIcon.appiconset/Contents.json
index 36d2c80..1d060ed 100644
--- a/MIBadgeButton/Images.xcassets/AppIcon.appiconset/Contents.json
+++ b/MIBadgeButton/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -1,5 +1,15 @@
{
"images" : [
+ {
+ "idiom" : "iphone",
+ "size" : "20x20",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "20x20",
+ "scale" : "3x"
+ },
{
"idiom" : "iphone",
"size" : "29x29",
@@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
+ {
+ "idiom" : "ipad",
+ "size" : "20x20",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "20x20",
+ "scale" : "2x"
+ },
{
"idiom" : "ipad",
"size" : "29x29",
@@ -59,6 +79,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "83.5x83.5",
+ "scale" : "2x"
}
],
"info" : {
diff --git a/MIBadgeButton/Images.xcassets/LaunchImage.launchimage/iOS Simulator Screen Shot Aug 10, 2015, 6.27.14 PM.png b/MIBadgeButton/Images.xcassets/LaunchImage.launchimage/iOS Simulator Screen Shot Aug 10, 2015, 6.27.14 PM.png
index 37aca95..7b82758 100644
Binary files a/MIBadgeButton/Images.xcassets/LaunchImage.launchimage/iOS Simulator Screen Shot Aug 10, 2015, 6.27.14 PM.png and b/MIBadgeButton/Images.xcassets/LaunchImage.launchimage/iOS Simulator Screen Shot Aug 10, 2015, 6.27.14 PM.png differ
diff --git a/MIBadgeButton/Images.xcassets/OS-X-Yosemite-for-iOS.imageset/OS-X-Yosemite-for-iOS.jpg b/MIBadgeButton/Images.xcassets/OS-X-Yosemite-for-iOS.imageset/OS-X-Yosemite-for-iOS.jpg
index 05d0b28..8f9995e 100644
Binary files a/MIBadgeButton/Images.xcassets/OS-X-Yosemite-for-iOS.imageset/OS-X-Yosemite-for-iOS.jpg and b/MIBadgeButton/Images.xcassets/OS-X-Yosemite-for-iOS.imageset/OS-X-Yosemite-for-iOS.jpg differ
diff --git a/MIBadgeButton/Images.xcassets/facebook.imageset/1408848343_facebook_circle_color.png b/MIBadgeButton/Images.xcassets/facebook.imageset/1408848343_facebook_circle_color.png
index f0f2ee5..f4d32db 100644
Binary files a/MIBadgeButton/Images.xcassets/facebook.imageset/1408848343_facebook_circle_color.png and b/MIBadgeButton/Images.xcassets/facebook.imageset/1408848343_facebook_circle_color.png differ
diff --git a/MIBadgeButton/Images.xcassets/pinterest.imageset/1408848335_pinterest-icon-circle-red.png b/MIBadgeButton/Images.xcassets/pinterest.imageset/1408848335_pinterest-icon-circle-red.png
index 88e7e98..39fa276 100644
Binary files a/MIBadgeButton/Images.xcassets/pinterest.imageset/1408848335_pinterest-icon-circle-red.png and b/MIBadgeButton/Images.xcassets/pinterest.imageset/1408848335_pinterest-icon-circle-red.png differ
diff --git a/MIBadgeButton/Images.xcassets/swift-logo-hero-2.imageset/swift-logo-hero-2.jpg b/MIBadgeButton/Images.xcassets/swift-logo-hero-2.imageset/swift-logo-hero-2.jpg
index 3013734..3fc390e 100644
Binary files a/MIBadgeButton/Images.xcassets/swift-logo-hero-2.imageset/swift-logo-hero-2.jpg and b/MIBadgeButton/Images.xcassets/swift-logo-hero-2.imageset/swift-logo-hero-2.jpg differ
diff --git a/MIBadgeButton/Images.xcassets/twitter.imageset/1408848408_twitter_circle.png b/MIBadgeButton/Images.xcassets/twitter.imageset/1408848408_twitter_circle.png
index 65b4100..157114a 100644
Binary files a/MIBadgeButton/Images.xcassets/twitter.imageset/1408848408_twitter_circle.png and b/MIBadgeButton/Images.xcassets/twitter.imageset/1408848408_twitter_circle.png differ
diff --git a/MIBadgeButton/ViewController.swift b/MIBadgeButton/ViewController.swift
index 31786f2..5b1aa80 100644
--- a/MIBadgeButton/ViewController.swift
+++ b/MIBadgeButton/ViewController.swift
@@ -15,12 +15,9 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
-
-
facebookButton.badgeString = "19"
- facebookButton.badgeTextColor = UIColor.whiteColor()
+ facebookButton.badgeTextColor = UIColor.white
facebookButton.badgeEdgeInsets = UIEdgeInsetsMake(10, 0, 0, 15)
twitterButton.badgeString = "180"
twitterButton.badgeEdgeInsets = UIEdgeInsetsMake(10, 0, 0, 15)
diff --git a/MIBadgeButtonTests/MIBadgeButtonTests.swift b/MIBadgeButtonTests/MIBadgeButtonTests.swift
index 5d0adb7..4091905 100644
--- a/MIBadgeButtonTests/MIBadgeButtonTests.swift
+++ b/MIBadgeButtonTests/MIBadgeButtonTests.swift
@@ -27,7 +27,7 @@ class MIBadgeButtonTests: XCTestCase {
func testPerformanceExample() {
// This is an example of a performance test case.
- self.measureBlock() {
+ self.measure() {
// Put the code you want to measure the time of here.
}
}
diff --git a/README.md b/README.md
index 885d6ef..acb9983 100644
--- a/README.md
+++ b/README.md
@@ -11,8 +11,13 @@ MIBadgeButton is badge button written in Swift with high UITableView/UICollectio
MIBadgeButton is available through [CocoaPods](http://cocoapods.org), to install
it simply add the following line to your Podfile:
+ # Swift 3
use_frameworks!
- pod "MIBadgeButton-Swift"
+ pod "MIBadgeButton-Swift", :git => 'https://github.com/mustafaibrahim989/MIBadgeButton-Swift.git', :branch => 'master'
+
+ # Swift 2
+ use_frameworks!
+ pod "MIBadgeButton-Swift", :git => 'https://github.com/mustafaibrahim989/MIBadgeButton-Swift.git', :branch => 'swift2'
Add MIBadgeButton to Storyboard or init with frame
diff --git a/screenshot.png b/screenshot.png
index 04c850c..555c721 100644
Binary files a/screenshot.png and b/screenshot.png differ