Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift rounded tab bar

@IBDesignable class TabBarWithCorners: UITabBar {
    @IBInspectable var color: UIColor?
    @IBInspectable var radii: CGFloat = 15.0

    private var shapeLayer: CALayer?

    override func draw(_ rect: CGRect) {
        addShape()
    }

    private func addShape() {
        let shapeLayer = CAShapeLayer()

        shapeLayer.path = createPath()
        shapeLayer.strokeColor = UIColor.gray.withAlphaComponent(0.1).cgColor
        shapeLayer.fillColor = color?.cgColor ?? UIColor.white.cgColor
        shapeLayer.lineWidth = 2
        shapeLayer.shadowColor = UIColor.black.cgColor
        shapeLayer.shadowOffset = CGSize(width: 0   , height: -3);
        shapeLayer.shadowOpacity = 0.2
        shapeLayer.shadowPath =  UIBezierPath(roundedRect: bounds, cornerRadius: radii).cgPath
        

        if let oldShapeLayer = self.shapeLayer {
            layer.replaceSublayer(oldShapeLayer, with: shapeLayer)
        } else {
            layer.insertSublayer(shapeLayer, at: 0)
        }

        self.shapeLayer = shapeLayer
    }

    private func createPath() -> CGPath {
        let path = UIBezierPath(
            roundedRect: bounds,
            byRoundingCorners: [.topLeft, .topRight],
            cornerRadii: CGSize(width: radii, height: 0.0))

        return path.cgPath
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.isTranslucent = true
        var tabFrame            = self.frame
        tabFrame.size.height    = 65 + (UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? CGFloat.zero)
        tabFrame.origin.y       = self.frame.origin.y +   ( self.frame.height - 65 - (UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? CGFloat.zero))
        self.layer.cornerRadius = 20
        self.frame            = tabFrame



        self.items?.forEach({ $0.titlePositionAdjustment = UIOffset(horizontal: 0.0, vertical: -5.0) })


    }

}
Comment

PREVIOUS NEXT
Code Example
Swift :: swift test if simulator 
Swift :: swift change status bar color 
Swift :: swift clear badge number 
Swift :: swift url encode string 
Swift :: swiftui tabview 
Swift :: swiftui console log 
Swift :: index string swift 
Swift :: unit testing swift 
Swift :: swift ui enum 
Swift :: swift center label 
Swift :: get day difference between two dates swift 
Swift :: dismiss keyboard when tap outside swift 5 
Swift :: swiftui textfield height 
Swift :: swiftui searchbar 
Swift :: set in swift 
Swift :: swiftui textfield editable false 
Swift :: check notification permission ios swift 
Swift :: uilabel set fon siz 
Swift :: Swift Trailing Closure 
Swift :: how to make month format in swift 
Swift :: Swift guard-let Statement 
Swift :: Swift Handling Errors Using do-catch Statement 
Swift :: swift comment 
Swift :: Create enum of Errors Swift 
Swift :: Swift Operators 
Swift :: Swift Nested Ternary Operators 
Swift :: Swift Access Elements from Dictionary 
Swift :: swift concurrency datatask before ios 15 
Swift :: swift uibutton text resets to default 
Swift :: xamarin get textview by id 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =