How to customize UISegmentedControl to change selected segment bottom border?
问题 I want to customize UISegmentedControl like this image: 回答1: Use extension with this self.segmentController.customizeAppearance(for: 1) Call addBorder method and pass your UISegmentedControl as a parameter static func addBorder(_ uiSegmentControl: UISegmentedControl){ var upperBorder: CALayer = CALayer() upperBorder.backgroundColor = UIColor.init(red: 255.0, green:255.0, blue: 255.0, alpha: 1.0).cgColor upperBorder.frame = CGRect(x: 0, y: Int(ceil(uiSegmentControl.subviews[0].bounds.height))