Add a view on top of a UISegmentedControl

647 views Asked by At

I want to add a view on top of a custom segmented control. Below is my code.

import UIKit

class CustomSegmentedControl: UISegmentedControl {

    override func awakeFromNib() {
        let overlayView = UIView(frame: frame)
        overlayView.backgroundColor = UIColor.yellowColor()
        superview?.addSubview(overlayView)
    }
}

But strangely it doesn't overlay the segmented control properly.

enter image description here

I can't figure out why this is happening. Any suggestion on how to resolve this?

Thank you.

0

There are 0 answers