Can't see any segmented control

#1

Why cannot I see segmented controls on the top of screen after activating constraints? Any suggestions to figure it out, thanks.

import UIKit
import MapKit

class MapViewController: UIViewController {

var mapView: MKMapView!

override func loadView() {
    mapView = MKMapView()
    
    view = mapView
    
    let segmentedControl = UISegmentedControl(items: ["Standard", "Hybrid", "Satellite"])
    segmentedControl.backgroundColor = UIColor.white.withAlphaComponent(0.5)
    segmentedControl.selectedSegmentIndex = 0
    
    segmentedControl.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(segmentedControl)
    
    let topConstraint = segmentedControl.topAnchor.constraint(equalTo: view.topAnchor)
    let leadingConstraint = segmentedControl.leadingAnchor.constraint(equalTo: view.leadingAnchor)
    let trailingConstraint = segmentedControl.trailingAnchor.constraint(equalTo: view.trailingAnchor)
    
    topConstraint.isActive = true
    leadingConstraint.isActive = true
    trailingConstraint.isActive = true
}

override func viewDidLoad() {
    super.viewDidLoad()
    
    print("MapViewController loaded its view.")
}

}

P.S. I’m using XCode 8.2.1 seems included Swift 3 in it

And could see this error from console with all output:

Painter Z index: 1023 is too large (max 255)
Painter Z index: 1023 is too large (max 255)
Painter Z index: 1023 is too large (max 255)
Painter Z index: 1023 is too large (max 255)
Painter Z index: 1023 is too large (max 255)
Painter Z index: 1023 is too large (max 255)
ERROR /BuildRoot/Library/Caches/com.apple.xbs/Sources/VectorKit_Sim/VectorKit-1230.32.8.29.9/GeoGL/GeoGL/GLCoreContext.cpp 1763: InfoLog SolidRibbonShader:
ERROR /BuildRoot/Library/Caches/com.apple.xbs/Sources/VectorKit_Sim/VectorKit-1230.32.8.29.9/GeoGL/GeoGL/GLCoreContext.cpp 1764: WARNING: Output of vertex shader ‘v_gradient’ not read by fragment shader

#2

Fixed it, just because I didn’t delete the Map View and the new class was not connected to the map’s view controller.

And the Error shows in console might be a bug which has been reported to Apple, there are two links in stackoverflow for this.

  1. http://stackoverflow.com/questions/39608231/warning-output-of-vertex-shader-v-gradient-not-read-by-fragment-shader
  2. http://stackoverflow.com/questions/41869703/app-freezes-on-main-thread-on-iphone-5c-but-not-on-iphone-6s/41874600?noredirect=1#comment70959393_41874600