From 0a3f5858e9e0396c0c22efd5dd1898441df213e4 Mon Sep 17 00:00:00 2001 From: Abdallah Nader Date: Mon, 6 Jul 2020 15:51:00 +0200 Subject: [PATCH 1/4] Update FluidTabBarItemContentView.swift --- FluidTabBarController/FluidTabBarItemContentView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FluidTabBarController/FluidTabBarItemContentView.swift b/FluidTabBarController/FluidTabBarItemContentView.swift index c0e99bd..afc7d86 100644 --- a/FluidTabBarController/FluidTabBarItemContentView.swift +++ b/FluidTabBarController/FluidTabBarItemContentView.swift @@ -175,8 +175,8 @@ open class FluidTabBarItemContentView: UIView { imageSize = UIScreen.main.scale == 3.0 ? 23.0 : 20.0 fontSize = UIScreen.main.scale == 3.0 ? 13.0 : 12.0 } else { - imageSize = 23.0 - fontSize = 10.0 + imageSize = 30.0 + fontSize = 13.0 } if !imageView.isHidden && !titleLabel.isHidden { From 1af4f4242b43fc46f782bdce937396f23a9fdef6 Mon Sep 17 00:00:00 2001 From: Abdallah Nader Date: Tue, 8 Dec 2020 12:16:06 +0200 Subject: [PATCH 2/4] Update FluidTabBarItem.swift --- FluidTabBarController/FluidTabBarItem.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/FluidTabBarController/FluidTabBarItem.swift b/FluidTabBarController/FluidTabBarItem.swift index bc53598..c4ff43e 100644 --- a/FluidTabBarController/FluidTabBarItem.swift +++ b/FluidTabBarController/FluidTabBarItem.swift @@ -68,6 +68,16 @@ open class FluidTabBarItem: UITabBarItem { didSet { self.contentView.tag = tag } } + open var isBadged :Bool{ + set { contentView.isBadged = newValue} + get { return contentView.isBadged ?? false} + } + + open var badgeNumber:String{ + set { contentView.badgeNumber = newValue} + get { return contentView.badgeNumber ?? ""} + } + let contentView: FluidTabBarItemContentView // MARK: Initializers From 68ea8a07a7be215ad5cdad2a0ecf1719bccb60bb Mon Sep 17 00:00:00 2001 From: Abdallah Nader Date: Tue, 8 Dec 2020 12:16:50 +0200 Subject: [PATCH 3/4] Update FluidTabBarItemContentView.swift --- .../FluidTabBarItemContentView.swift | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/FluidTabBarController/FluidTabBarItemContentView.swift b/FluidTabBarController/FluidTabBarItemContentView.swift index afc7d86..be541b0 100644 --- a/FluidTabBarController/FluidTabBarItemContentView.swift +++ b/FluidTabBarController/FluidTabBarItemContentView.swift @@ -114,6 +114,19 @@ open class FluidTabBarItemContentView: UIView { } } } + + open var isBadged: Bool? { + didSet { + self.updateLayout() + } + } + + open var badgeNumber: String? { + didSet { + self.badgeLabel.text = badgeNumber + self.updateLayout() + } + } open var imageView: UIImageView = { let imageView = UIImageView(frame: .zero) @@ -128,6 +141,21 @@ open class FluidTabBarItemContentView: UIView { titleLabel.textAlignment = .center return titleLabel }() + + open var badgeView: UIView = { + let badgeView = UIView(frame: .zero) + badgeView.backgroundColor = .red + badgeView.layer.cornerRadius = 10 + return badgeView + }() + + open var badgeLabel: UILabel = { + let titleLabel = UILabel(frame: .zero) + titleLabel.backgroundColor = .clear + titleLabel.textColor = .white + titleLabel.textAlignment = .center + return titleLabel + }() internal let imageViewContainer = UIView() @@ -140,6 +168,8 @@ open class FluidTabBarItemContentView: UIView { addSubview(imageViewContainer) imageViewContainer.addSubview(imageView) addSubview(titleLabel) + addSubview(badgeView) + badgeView.addSubview(badgeLabel) } public required init?(coder aDecoder: NSCoder) { @@ -195,6 +225,18 @@ open class FluidTabBarItemContentView: UIView { width: imageSize, height: imageSize ) + if isBadged ?? false{ + badgeLabel.font = UIFont.systemFont(ofSize: fontSize) + badgeLabel.sizeToFit() + badgeView.frame = CGRect( + x: (width/2) + (UIScreen.main.scale == 3.0 ? 6.0 : 5.0) , + y: 2, + width: 20, + height: 20 + ) + }else{ + badgeView.frame = .zero + } } else { titleLabel.frame = CGRect( x: (width - titleLabel.bounds.size.width) / 2.0, @@ -208,6 +250,18 @@ open class FluidTabBarItemContentView: UIView { width: imageSize, height: imageSize ) + if isBadged ?? false{ + badgeView.frame = CGRect( + x: (width/2) + (UIScreen.main.scale == 3.0 ? 6.0 : 5.0) , + y: 2, + width: 20, + height: 20 + ) + badgeLabel.font = UIFont.systemFont(ofSize: 10) + badgeLabel.sizeToFit() + }else{ + badgeView.frame = .zero + } } } else if !imageView.isHidden { imageViewContainer.frame = CGRect( @@ -217,7 +271,7 @@ open class FluidTabBarItemContentView: UIView { height: imageSize ) } else if !titleLabel.isHidden { - titleLabel.font = UIFont.systemFont(ofSize: fontSize) + titleLabel.font = UIFont.systemFont(ofSize: 10) titleLabel.sizeToFit() titleLabel.frame = CGRect( x: (width - titleLabel.bounds.size.width) / 2.0, @@ -228,6 +282,7 @@ open class FluidTabBarItemContentView: UIView { } imageView.frame = imageViewContainer.bounds + badgeLabel.frame = badgeView.bounds animator.initialize() if selected { From 19101ee96d0a501cdad735c93003326080cb9c9b Mon Sep 17 00:00:00 2001 From: Abdallah Nader Date: Sun, 14 Mar 2021 13:33:33 +0200 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 97628a4..a3a8fae 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ It is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile: ```ruby -pod 'FluidTabBarController' +pod 'FluidTabBarController', :git => 'https://github.com/abdoh476/FluidBottomNavigation-ios' ``` ## Usage