Minitour / AZTabBarController

A custom tab bar controller for iOS written in Swift 4.2
MIT License
348 stars 65 forks source link

AZTabBar with shadow from top #19

Closed escully27 closed 7 years ago

escully27 commented 7 years ago

Hello - the tabBar is working well. Just curious if there was a way to add a black shadow extending from the top border into the view. This code has no effect...

tabController.view.layer.shadowColor = UIColor.black.cgColor tabController.view.layer.masksToBounds = false tabController.view.layer.shadowOffset = CGSize.zero tabController.view.layer.shadowRadius = 50 tabController.view.layer.shadowOpacity = 1.0

Thanks!

Minitour commented 7 years ago

@escully27 Hi, Yes you can customize the tab bar in a variety of ways. Checkout issue #11, where I explain how to do so. In the issue you can find a section where I add a shadow to the tab bar.

If you were unable to achieve your goal let me know.

Edit:

I forgot the issue I mentioned was on an older version of the framework, so now you don't have to do most of the steps.

Instead this is all you have to do:

let container = tabBar?.buttonsContainer
container.layer.shadowOffset = CGSize(width: 0, height: -2)
container.layer.shadowRadius = 10
container.layer.shadowOpacity = 0.1
container.layer.shadowColor = UIColor.black.cgColor
escully27 commented 7 years ago

Thanks for the quick response.. And great, I was trying to filter the unnecessary steps for that issue. Add this code to the AZTabBarContoller.swift I am guessing?

Minitour commented 7 years ago

@escully27 You add this code in the controller in which you are setting up the tab bar. (In the viewDidLoad)

escully27 commented 7 years ago

There is no item named buttonsContainer .. all I have is buttonsContainerView because I added that extension as seen in issue #11... but that isn't working anyways...

Minitour commented 7 years ago

@escully27 Make sure you are using the latest release: https://github.com/Minitour/AZTabBarController/blob/master/Sources/AZTabBarController.swift#L225

escully27 commented 7 years ago

How do I update via cocoapods? I just did pod ' AZTabBar' for current version. Thanks for help so far!!

Minitour commented 7 years ago

pod update And check in the terminal to see that AZTabBar is 1.2.1

escully27 commented 7 years ago

Updated pod... unfortunately not working still :( This is what I have...

let container = tabController.buttonsContainer container?.layer.shadowOffset = CGSize(width: 0, height: -2) container?.layer.shadowRadius = 10 container?.layer.shadowOpacity = 0.1 container?.layer.shadowColor = UIColor.black.cgColor container?.layer.masksToBounds = false

Minitour commented 7 years ago

@escully27 What is the current UI result? can you submit an image?

escully27 commented 7 years ago

img_8456

Minitour commented 7 years ago

Can you also include your viewDidLoad() where you init the tab bar?

escully27 commented 7 years ago
    var icons = [String]()
    icons.append("home.std")
    icons.append("graph.std")
    icons.append("new.std")
    icons.append("team_std")
    icons.append("prof.std")

    var selectedIcons = [String]()
    selectedIcons.append("home.sel")
    selectedIcons.append("graph.sel")
    selectedIcons.append("new.sel")
    selectedIcons.append("team.sel")
    selectedIcons.append("prof.sel")

    var tabController = AZTabBarController.insert(into: self, withTabIconNames: icons, andSelectedIconNames: selectedIcons)
    tabController.highlightColor = .gray
    tabController.highlightedBackgroundColor = .clear
    tabController.buttonsBackgroundColor = .white
    tabController.selectionIndicatorColor = sttblue
    tabController.selectionIndicatorHeight = 3.0
    tabController.separatorLineVisible = false
    tabController.animateTabChange = true
    tabController.tabBarHeight = 70.0
    tabController.ignoreIconColors = true

    let home = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Home") as! Home
    let insights = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Insights") as! Insights
    let create = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Create") as! Create
    let teams = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Teams") as! Teams
    let profile = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Profile") as! Profile

    tabController.setViewController(home, atIndex: 0)
    tabController.setViewController(insights, atIndex: 1)
    tabController.setViewController(create, atIndex: 2)
    tabController.setViewController(teams, atIndex: 3)
    tabController.setViewController(profile, atIndex: 4)

    let container = tabController.buttonsContainer
    container?.layer.shadowOffset = CGSize(width: 0, height: -2)
    container?.layer.shadowRadius = 10
    container?.layer.shadowOpacity = 1.0
    container?.layer.shadowColor = UIColor.black.cgColor

    view.backgroundColor = .white
    view.addSubview(tabController.view)
Minitour commented 7 years ago

@escully27 I found the issue, will be fixed next release. Here is your temporary solution:

Go to AZTabBarController.swift. In the loadView function replace the order:

view.addSubview(buttonsContainer)
view.addSubview(controllersContainer)
view.addSubview(separatorLine)

with this order:

view.addSubview(controllersContainer)
view.addSubview(buttonsContainer)
view.addSubview(separatorLine)
escully27 commented 7 years ago

Amazing! Thanks

Minitour commented 7 years ago

Fixed with 1.2.2 release.