Change Google's map SDK current location button possition [duplicate] - swift

I am using google maps in my project i want to show my location button
a bit up how should i do that using swift

You can change the position of the MapControls by set the padding for your map view .
let mapView = GMSMapView()
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 50)
It will change the padding of the my location control. From bottom 50px and from right 50px
Refer the below screenshot which added the padding of 50px from bottom and right.

Update for swift 4 : just change the position of my location button only
for object in self.mapView.subviews{
if(object.theClassName == "GMSUISettingsPaddingView"){
for view in object.subviews{
if(view.theClassName == "GMSUISettingsView"){
for btn in view.subviews{
if(btn.theClassName == "GMSx_QTMButton"){
var frame = btn.frame
frame.origin.y = frame.origin.y - 100
btn.frame = frame
}
}
}
}
}
}
public extension NSObject {
public var theClassName: String {
return NSStringFromClass(type(of: self))
}
}

Like Subramanian, this works very well :
mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)
This is perfect if you have a navigation bar in your app.

Here's my function for Google Maps SDK 5.1.0, since the button's class was renamed to 'GMSx_MDCFloatingButton' in case someone needs an updated approach.
Also depending on your implementation you might want to call this on viewDidAppear().
func moveLocationButton(){
for object in self.googleMapsView!.subviews{
if(object.thisClassName == "GMSUISettingsPaddingView"){
for view in object.subviews{
if(view.thisClassName == "GMSUISettingsView"){
for btn in view.subviews{
if(btn.theClassName == "GMSx_MDCFloatingButton"){
var frame = btn.frame
frame.origin.x = frame.origin.x - 50
frame.origin.y = frame.origin.y - 150
btn.frame = frame
}
}
}
}
}
}
}
public extension NSObject {
var thisClassName: String {
return NSStringFromClass(type(of: self))
}
}

I would recommend to change button position by correcting constraint instead of changing frame.origin. I got it worked by changing frame.origin placing it into viewDidAppear only. Neither viewWillApper nor viewWillLayoutSubviews were correct methods to call from. However I managed it work perfectly calling constraint changing from viewDidLoad. And I used snapkit, but it is not a big deal to get it done natively
private func changeCurrentLocationButtonPosition(of mapView: GMSMapView) {
for object in mapView.subviews where object.theClassName == "GMSUISettingsPaddingView" {
for view in object.subviews where view.theClassName == "GMSUISettingsView" {
for btn in view.subviews where btn.theClassName == "GMSx_MDCFloatingButton" {
btn.snp.makeConstraints({ maker in
maker.left.equalToSuperview().offset(15)
})
btn.snp.makeConstraints({ maker in
maker.bottom.equalToSuperview().offset(-30)
})
return
}
}
}
}

Use this function and call this at viewDidLayoutSubviews()
func changeLocationBtnFrame(){
self.mapView.settings.myLocationButton = true
for obj in self.mapView.subviews{
if String(describing: obj.classForCoder) == "GMSUISettingsPaddingView"{
for viw in obj.subviews{
if String(describing: viw.classForCoder) == "GMSUISettingsView"{
for btn in viw.subviews{
if String(describing: btn.classForCoder) == "GMSx_MDCFloatingButton"{
var frame = btn.frame
btn.frame = CGRect(x: 316, y: 0, width: 56, height: 56)
//USE you want frame this line
break
}
}
break
}
}
break
}
}
}

Related

How to properly center UITabBar items vertically for UITabBar with larger height and no item titles?

I'm working on a custom UITabBar that has a larger height, custom shadow and no item titles.
I am using the following code for my custom UITabBar class to achieve this like:
class CustomUITabBar: UITabBar {
#IBInspectable private var height: CGFloat = .zero
override func sizeThatFits(_ size: CGSize) -> CGSize {
guard let window = UIApplication.shared.windows.first else {
return super.sizeThatFits(size)
}
var sizeThatFits = super.sizeThatFits(size)
if #available(iOS 11.0, *) {
sizeThatFits.height = height + window.safeAreaInsets.bottom
} else {
sizeThatFits.height = height
}
return sizeThatFits
}
}
Here is the result: On iPhones that have notch (iPhone X, XS, 11, etc.) it looks fine, icons are centered properly, like so:
But on iPhones that have home button instead, tab bar items are not propery centered vertically. Is there a solution to this?
Now they are not centered as I see it on both devices. You can play around with this code:
guard let items = tabBar.items else { return }
for item in items {
item.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
it adjusts image of TabBarItem:)
With this settings they are going to be centered in each TabBarItem.

Add a CollectionView in ScrollView

I have a problem in implementing a UI. I actually want to add a collection view at the end of a scroll view. I don't exactly know how to proceed and I think I'm stuck...
Here is my call to add the views in the scroll view.
if training?.description != nil {
//add description
addTraining(description: (training?.description)!)
}
if training?.question1 != nil{
addTraining(question1: (training?.question1)!)
}
if training?.question2 != nil{
addTraining(question2: (training?.question2)!)
}
// ADD COLLECTION VIEW AT BOTTOM
Here would be the respective functions.
private func addTraining(description: String) {
trainingDescriptionTitle.text = "Description"
trainingDescriptionContent.text = description
trainingDescriptionContent.sizeToFit()
trainingDescriptionContent.frame.size = CGSize(width: view.frame.width - 10, height: trainingDescriptionContent.frame.height)
trainingDescriptionContainerView.addView(newView: trainingDescriptionTitle)
trainingDescriptionContainerView.addView(newView: trainingDescriptionContent)
scrollView.addView(newView: trainingDescriptionContainerView)
}
private func addTraining(question1: String) {
trainingQuestion1Title.text = "What You Will Learn"
trainingQuestion1Content.text = question1
trainingQuestion1Content.sizeToFit()
trainingQuestion1Content.frame.size = CGSize(width: view.frame.width - 10, height: trainingQuestion1Content.frame.height)
trainingQuestion1ContainerView.addView(newView: trainingQuestion1Title)
trainingQuestion1ContainerView.addView(newView: trainingQuestion1Content)
scrollView.addView(newView: trainingQuestion1ContainerView)
}
private func addTraining(question2: String) {
trainingQuestion2Title.text = "Who Should Take This"
trainingQuestion2Content.text = question2
trainingQuestion2Content.sizeToFit()
trainingQuestion2Content.frame.size = CGSize(width: view.frame.width - 10, height: trainingQuestion2Content.frame.height)
trainingQuestion2ContainerView.addView(newView: trainingQuestion2Title)
trainingQuestion2ContainerView.addView(newView: trainingQuestion2Content)
scrollView.addView(newView: trainingQuestion2ContainerView)
}
how would I do the same in adding a collectionView in the scrollView?
Thanks to anyone who'll answer.
Here would be the result:

UISlider not updating values

apologies if this is a stupid question. I can't seem to get my slider to update its value as its being interacted with. (I'm going to point everyone to the very last method in this long code)
class CustomSlider: UISlider {
override func trackRect(forBounds bounds: CGRect) -> CGRect {
var rect = super.trackRect(forBounds: bounds)
rect.size.height = 7
return rect
}
}
class FactionButton: CustomSlider {
var factionSlider = CustomSlider(frame: CGRect(x: 15, y: 542, width: 386, height: 57))
func factionBalanceSlider(){
factionSlider.minimumValueImage = #imageLiteral(resourceName: "Alliance Slider")
factionSlider.maximumValueImage = #imageLiteral(resourceName: "Horde Slider")
factionSlider.setThumbImage(#imageLiteral(resourceName: "Thumb Image"), for: .normal)
factionSlider.minimumTrackTintColor = UIColor(red:0.08, green:0.33, blue:0.69, alpha:0.8)
factionSlider.maximumTrackTintColor = UIColor(red:1.00, green:0.00, blue:0.00, alpha:0.59)
factionSlider.setValue(0.5, animated: true)
factionSlider.isContinuous = false
factionSlider.addTarget(self, action: #selector(recordFactionBalance(sender:)), for: .valueChanged)
}
func getSlider() -> CustomSlider {
return factionSlider
}
override func trackRect(forBounds bounds: CGRect) -> CGRect {
var customBounds = super.trackRect(forBounds: bounds)
customBounds.size.height = 10
return customBounds
}
#objc func recordFactionBalance(sender: CustomSlider){
//also calculates balance and adds it into the quiz data
print("hi")
print(sender.value) //It's this part that doesn't work
}
}
It's this bit nearest to the bottom that has the issue. (Everything else is fine) The action function doesn't seem to be triggered at all, even when I'm interacting with it. Neither print statements are being executed. Any ideas why?
Cheers
From the getSlider(), i can guess you are using this class as a utility to get the CustomSlider. So, i suspect you are adding the slider to the view as below,
let container = FactionButton()
container.factionBalanceSlider()
let slider = container.getSlider()
self.view.addSubview(slider)
If you will not add the container to the view which is set as the receiver for .valueChange event so it will not get any event. To receive events you also need to add the container in the view as below,
self.view.addSubview(container)

Storing UIView with children

Im working on a 2x2 grid with everyone of them having a UIView and a child label with text and background color.
I generate the UIView with a for loop like this:
// Generatin answer cube buttons
for var i = 0; i < cubeCount; i++
{
// two answers case
if(cubeCount < 3)
{
var btn = button(xpos, y: ypos, width: screenWidth, height: (screenHeight * 2));
var lbl = labelis("\(i)", btn: btn)
btn.addSubview(lbl)
xpos = xpos + (screenWidth + 10);
self.view.addSubview(btn);
}
// 3+ answers case
else
{
var btn = button(xpos, y: ypos, width: screenWidth, height: screenHeight);
var lbl = labelis("\(i)", btn: btn)
btn.addSubview(lbl)
xpos = xpos + (screenWidth + 10)
self.view.addSubview(btn)
// change row in case of more than 2 answers
if(i == 1)
{
xpos = 20
ypos = ypos + (screenHeight + 10)
}
}
I also have a tapGesture function letting me know when I click on one of the answer cube.
My problem here is that, when clicking on one of the cube, I would like to access all the cubes and change their label's background color.
I though about storing the UIView into an array so I could act on them from the tapGesture function, but I don't see how I could make this work.
I though that maybe someone could guide me through the way of dealing with this.
thanks.
In the click handler of cube button try following code:
for subview in view.subviews as [UIView] {
if let cubeButton = subview as? button {
//Do something with this cubeButton here.
}
}
So I've found a solution to my problem so I answer my own question for people who might look into this in the future:
I've created an array:
var answerData:[UIView] = [];
and added my UIView along the way for those I wanted to keep stored
var uiviewvariable = UIView()
answerData.append(uiviewVariable)
then, on my tapGesture function, when the user tap one of the view, I can call for the array and use act on the UIViews
// Accessing stored UIView
for(var i = 0; i < answerData.count; i++){
// Accessing subviews
for subview in answerData[i].subviews as [UIView]
{
if subview.tag == 0
{
if let label = subview as? UILabel {
// do something with label inside the views
}
}
}
}
for some reason I use something similar than Abdullah's answer for selecting my labels but I didn't managed to make his snippet work.

Is it possible to change UITabBarItem badge color

I want to change background color of UITabBarItem badge but can't find any resource on how to make it.
UITabBarItem has this available since iOS 10.
var badgeColor: UIColor? { get set }
It's also available via appearence.
if #available(iOS 10, *) {
UITabBarItem.appearance().badgeColor = .green
}
reference docs:
https://developer.apple.com/reference/uikit/uitabbaritem/1648567-badgecolor
Changing the badge-color is now natively supported in iOS 10 and later using the badgeColor property inside your UITabBarItem. See the apple docs for more infos on the property.
Example:
Swift 3: myTab.badgeColor = UIColor.blue
Objective-C: [myTab setBadgeColor:[UIColor blueColor]];
I wrote this piece of code for my app, but I have only tested it in iOS 7.
for (UIView* tabBarButton in self.tabBar.subviews) {
for (UIView* badgeView in tabBarButton.subviews) {
NSString* className = NSStringFromClass([badgeView class]);
// looking for _UIBadgeView
if ([className rangeOfString:#"BadgeView"].location != NSNotFound) {
for (UIView* badgeSubview in badgeView.subviews) {
NSString* className = NSStringFromClass([badgeSubview class]);
// looking for _UIBadgeBackground
if ([className rangeOfString:#"BadgeBackground"].location != NSNotFound) {
#try {
[badgeSubview setValue:[UIImage imageNamed:#"YourCustomImage.png"] forKey:#"image"];
}
#catch (NSException *exception) {}
}
if ([badgeSubview isKindOfClass:[UILabel class]]) {
((UILabel *)badgeSubview).textColor = [UIColor greenColor];
}
}
}
}
}
You're only able to update the badge background with an image, not a color. I have also exposed the badge label if you wanted to update that in some way.
Its important to note that this code must be called after setting the tabBarItem.badgeValue!
EDIT: 4/14/14
The above code will work in iOS 7 when called anywhere. To get it working in iOS 7.1 call it in the view controllers -viewWillLayoutSubviews.
EDIT: 12/22/14
Here's an updated snippet which I'm currently using. I put the code in a category extension for simplicity.
- (void)badgeViews:(void (^)(UIView* badgeView, UILabel* badgeLabel, UIView* badgeBackground))block {
if (block) {
for (UIView* tabBarButton in self.subviews) {
for (UIView* badgeView in tabBarButton.subviews) {
NSString* className = NSStringFromClass([badgeView class]);
if ([className rangeOfString:#"BadgeView"].location != NSNotFound) {
UILabel* badgeLabel;
UIView* badgeBackground;
for (UIView* badgeSubview in badgeView.subviews) {
NSString* className = NSStringFromClass([badgeSubview class]);
if ([badgeSubview isKindOfClass:[UILabel class]]) {
badgeLabel = (UILabel *)badgeSubview;
} else if ([className rangeOfString:#"BadgeBackground"].location != NSNotFound) {
badgeBackground = badgeSubview;
}
}
block(badgeView, badgeLabel, badgeBackground);
}
}
}
}
}
Then when you're ready to call it, it'll look like this.
[self.tabBar badgeViews:^(UIView *badgeView, UILabel *badgeLabel, UIView *badgeBackground) {
}];
EDIT: 11/16/15
It's been brought to my attention that some people need a little more clarity on what's happening in this code. The for loops are searching for a few views which are not publicly accessible. By checking if the views class name contains a part of the expected name, it's ensuring to reach the intended view while not setting off any possible red flags by Apple. Once everything has been located, a block is executed with easy access to these views.
It's noteworthy that the possibility exists for this code to stop working in a future iOS update. For example these internal views could one day acquire different class names. However the chances of that are next to none since even internally Apple rarely refactors classes to this nature. But even if they were to, it would be something along the title of UITabBarBadgeView, which would still reach the expected point in code. Being that iOS9 is well out the door and this code is still working as intended, you can expect this problem to never arise.
I have the same problem and solved it by creating a little category that replace the BadgeView with an UILabel that you can customize easily.
https://github.com/enryold/UITabBarItem-CustomBadge/
For people using Swift, I managed to improve on TimWhiting answer in order to have the badge view working on any screen size and any orientation.
extension UITabBarController {
func setBadges(badgeValues: [Int]) {
for view in self.tabBar.subviews {
if view is CustomTabBadge {
view.removeFromSuperview()
}
}
for index in 0...badgeValues.count-1 {
if badgeValues[index] != 0 {
addBadge(index, value: badgeValues[index], color:UIColor(paletteItem: .Accent), font: UIFont(name: Constants.ThemeApp.regularFontName, size: 11)!)
}
}
}
func addBadge(index: Int, value: Int, color: UIColor, font: UIFont) {
let badgeView = CustomTabBadge()
badgeView.clipsToBounds = true
badgeView.textColor = UIColor.whiteColor()
badgeView.textAlignment = .Center
badgeView.font = font
badgeView.text = String(value)
badgeView.backgroundColor = color
badgeView.tag = index
tabBar.addSubview(badgeView)
self.positionBadges()
}
override public func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.positionBadges()
}
// Positioning
func positionBadges() {
var tabbarButtons = self.tabBar.subviews.filter { (view: UIView) -> Bool in
return view.userInteractionEnabled // only UITabBarButton are userInteractionEnabled
}
tabbarButtons = tabbarButtons.sort({ $0.frame.origin.x < $1.frame.origin.x })
for view in self.tabBar.subviews {
if view is CustomTabBadge {
let badgeView = view as! CustomTabBadge
self.positionBadge(badgeView, items:tabbarButtons, index: badgeView.tag)
}
}
}
func positionBadge(badgeView: UIView, items: [UIView], index: Int) {
let itemView = items[index]
let center = itemView.center
let xOffset: CGFloat = 12
let yOffset: CGFloat = -14
badgeView.frame.size = CGSizeMake(17, 17)
badgeView.center = CGPointMake(center.x + xOffset, center.y + yOffset)
badgeView.layer.cornerRadius = badgeView.bounds.width/2
tabBar.bringSubviewToFront(badgeView)
}
}
class CustomTabBadge: UILabel {}
No you can't change the color but you can use your own badges instead. Add this extension at the file scope and you can customise the badges however you like. Just call self.tabBarController!.setBadges([1,0,2]) in any of your root view controllers.
To be clear that is for a tab bar with three items, with the badge values going from left to right.
extension UITabBarController {
func setBadges(badgeValues:[Int]){
var labelExistsForIndex = [Bool]()
for value in badgeValues {
labelExistsForIndex.append(false)
}
for view in self.tabBar.subviews {
if view.isKindOfClass(PGTabBadge) {
let badgeView = view as! PGTabBadge
let index = badgeView.tag
if badgeValues[index]==0 {
badgeView.removeFromSuperview()
}
labelExistsForIndex[index]=true
badgeView.text = String(badgeValues[index])
}
}
for var i=0;i<labelExistsForIndex.count;i++ {
if labelExistsForIndex[i] == false {
if badgeValues[i] > 0 {
addBadge(i, value: badgeValues[i], color:UIColor(red: 4/255, green: 110/255, blue: 188/255, alpha: 1), font: UIFont(name: "Helvetica-Light", size: 11)!)
}
}
}
}
func addBadge(index:Int,value:Int, color:UIColor, font:UIFont){
let itemPosition = CGFloat(index+1)
let itemWidth:CGFloat = tabBar.frame.width / CGFloat(tabBar.items!.count)
let bgColor = color
let xOffset:CGFloat = 12
let yOffset:CGFloat = -9
var badgeView = PGTabBadge()
badgeView.frame.size=CGSizeMake(17, 17)
badgeView.center=CGPointMake((itemWidth * itemPosition)-(itemWidth/2)+xOffset, 20+yOffset)
badgeView.layer.cornerRadius=badgeView.bounds.width/2
badgeView.clipsToBounds=true
badgeView.textColor=UIColor.whiteColor()
badgeView.textAlignment = .Center
badgeView.font = font
badgeView.text = String(value)
badgeView.backgroundColor = bgColor
badgeView.tag=index
tabBar.addSubview(badgeView)
}
}
class PGTabBadge: UILabel {
}
Swift 3 Here is an updated version of #Kirualex's answer (who improved on #TimWhiting's answer) for Swift 3.
extension UITabBarController {
func setBadges(badgeValues: [Int]) {
for view in self.tabBar.subviews {
if view is CustomTabBadge {
view.removeFromSuperview()
}
}
for index in 0...badgeValues.count-1 {
if badgeValues[index] != 0 {
addBadge(index: index, value: badgeValues[index], color: UIColor.blue, font: UIFont(name: "Helvetica-Light", size: 11)!)
}
}
}
func addBadge(index: Int, value: Int, color: UIColor, font: UIFont) {
let badgeView = CustomTabBadge()
badgeView.clipsToBounds = true
badgeView.textColor = UIColor.white
badgeView.textAlignment = .center
badgeView.font = font
badgeView.text = String(value)
badgeView.backgroundColor = color
badgeView.tag = index
tabBar.addSubview(badgeView)
self.positionBadges()
}
override open func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.positionBadges()
}
// Positioning
func positionBadges() {
var tabbarButtons = self.tabBar.subviews.filter { (view: UIView) -> Bool in
return view.isUserInteractionEnabled // only UITabBarButton are userInteractionEnabled
}
tabbarButtons = tabbarButtons.sorted(by: { $0.frame.origin.x < $1.frame.origin.x })
for view in self.tabBar.subviews {
if view is CustomTabBadge {
let badgeView = view as! CustomTabBadge
self.positionBadge(badgeView: badgeView, items:tabbarButtons, index: badgeView.tag)
}
}
}
func positionBadge(badgeView: UIView, items: [UIView], index: Int) {
let itemView = items[index]
let center = itemView.center
let xOffset: CGFloat = 12
let yOffset: CGFloat = -14
badgeView.frame.size = CGSize(width: 17, height: 17)
badgeView.center = CGPoint(x: center.x + xOffset, y: center.y + yOffset)
badgeView.layer.cornerRadius = badgeView.bounds.width/2
tabBar.bringSubview(toFront: badgeView)
}
}
class CustomTabBadge: UILabel {}
It appears that no. You may only set the value.
From Apple's documentation badge is:
Text that is displayed in the upper-right corner of the item with a
surrounding red oval.
You need to specify tab item at index to change badge color, #available in iOS 10 ,
if #available(iOS 10.0, *)
{
self.kAppTabBarController.tabBar.items![1].badgeColor = YOUR_COLOR
}
You can now do it in the storyboard too, by selecting your tab bar item and going to the attributes inspector.
Since iOS 15 has different approach, what worked in my case:
let appearance = UITabBarAppearance()
appearance.configureWithTransparentBackground()
let barAppearance = UITabBarItemAppearance()
barAppearance.normal.badgeBackgroundColor = .green
barAppearance.normal.badgeTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
appearance.stackedLayoutAppearance = barAppearance
tabBar.standardAppearance = appearance
YES, But the only possible solution is to create a custom Tabbar and creating your custom tabbar badge icon. You will find many article/code for creating custom tabbar.
// change TabBar BadgeView background Color
-(void)changeTabBarBadgeViewBgColor:(UITabBar*)tabBar {
for (UIView* tabBarButton in tabBar.subviews) {
for (UIView* badgeView in tabBarButton.subviews) {
NSString* className = NSStringFromClass([badgeView class]);
// looking for _UIBadgeView
if ([className rangeOfString:#"BadgeView"].location != NSNotFound) {
for (UIView* badgeSubview in badgeView.subviews) {
NSString* className = NSStringFromClass([badgeSubview class]);
// looking for _UIBadgeBackground
if ([className rangeOfString:#"BadgeBackground"].location != NSNotFound) {
#try {
[badgeSubview setValue:nil forKey:#"image"];
[badgeSubview setBackgroundColor:[UIColor blueColor]];
badgeSubview.clipsToBounds = YES;
badgeSubview.layer.cornerRadius = badgeSubview.frame.size.height/2;
}
#catch (NSException *exception) {}
}
if ([badgeSubview isKindOfClass:[UILabel class]]) {
((UILabel *)badgeSubview).textColor = [UIColor greenColor];
}
}
}
}
}
}
Hm...it's very easy.
[[self tabBarItem] setBadgeColor:[UIColor greenColor]];
Add below lines of code in UITabBarController :
class RootTabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
if #available(iOS 13.0, *) {
let appearance = tabBar.standardAppearance.copy()
setTabBarItemBadgeAppearance(appearance.stackedLayoutAppearance)
setTabBarItemBadgeAppearance(appearance.inlineLayoutAppearance)
setTabBarItemBadgeAppearance(appearance.compactInlineLayoutAppearance)
tabBar.standardAppearance = appearance
if #available(iOS 15.0, *) {
tabBar.scrollEdgeAppearance = appearance
}
}
// Do any additional setup after loading the view.
}
#available(iOS 13.0, *)
private func setTabBarItemBadgeAppearance(_ itemAppearance: UITabBarItemAppearance) {
itemAppearance.normal.badgeBackgroundColor = UIColor.colorBlue207DFF
}
}
Since iOS 15 / Xcode 13, you have to set stackedLayoutAppearance property to change badge color on UITabBarItem. Change just ".blue" with you own color:
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .blue
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = appearance
}
Tested on Xcode 14.1 / iOS 16.
Take a look here # UITabbarItem-CustomBadge.
A complete demonstration is following
it takes only two line of code, if you want to use the default implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//supplying the animation parameter
[UITabBarItem setDefaultAnimationProvider:[[DefaultTabbarBadgeAnimation alloc] init]];
[UITabBarItem setDefaultConfigurationProvider:[[DefaultSystemLikeBadgeConfiguration alloc] init]];
//rest of your code goes following...
return YES;
}