Xlpagertabstrip: Is it possible to add a shadow below the tabbar like on Android?

Created on 11 Oct 2016  路  5Comments  路  Source: xmartlabs/XLPagerTabStrip

Thank you for this great component!
Is it possible to add a shadow below the tabbar? Like in the Android Tabbar?

An example from the YouTube app:
youtube app tab bar shadow

And if yes, how? Thank you!

awaiting response

Most helpful comment

try this code after super.viewDidLoad()

        self.buttonBarView.layer.shadowRadius = 1.0
        self.buttonBarView.layer.shadowColor = UIColor.black.cgColor
        self.buttonBarView.layer.shadowOffset = CGSize(width: 0, height: 1)
        self.buttonBarView.layer.shadowOpacity = 0.5
        self.buttonBarView.layer.masksToBounds = false

All 5 comments

You could add it directly to the view controllers that are part of the view.

If you still need this this is what I did:

func addTopShadow() {
        let frame = CGRect(x: 0, y: 35, width: self.view.frame.width, height: 6)

        let backgroundView = UIView(frame: frame)
        self.view.addSubview(backgroundView)

        //A linear Gradient Consists of two colours: top colour and bottom colour
        let topColor = UIColor.black
        let bottomColor = UIColor.clear

        //Add the top and bottom colours to an array and setup the location of those two.
        let gradientColors: [CGColor] = [topColor.cgColor, bottomColor.cgColor]
        let gradientLocations: [CGFloat] = [0.0, 1.0]

        //Create a Gradient CA layer
        let gradientLayer = CAGradientLayer()
        gradientLayer.colors = gradientColors
        gradientLayer.locations = gradientLocations as [NSNumber]?
        gradientLayer.frame = frame
        gradientLayer.opacity = 0.2
        backgroundView.layer.insertSublayer(gradientLayer, at: 0)
        backgroundView.layer.zPosition = 100

}

try this code after super.viewDidLoad()

        self.buttonBarView.layer.shadowRadius = 1.0
        self.buttonBarView.layer.shadowColor = UIColor.black.cgColor
        self.buttonBarView.layer.shadowOffset = CGSize(width: 0, height: 1)
        self.buttonBarView.layer.shadowOpacity = 0.5
        self.buttonBarView.layer.masksToBounds = false

As it was mentioned by @scinfu, the best way should be to add the shadow to the buttonBarView.

What if I wanted to actually use a CAGradientLayer?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

emrecanozturk picture emrecanozturk  路  5Comments

luminkhant picture luminkhant  路  4Comments

alexanderkhitev picture alexanderkhitev  路  4Comments

Ariavm95 picture Ariavm95  路  4Comments

dowhilenet picture dowhilenet  路  4Comments