Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3.  
  4. // Note: you may need to set the layout contraints for it by yourself
  5. // to make it displayed correctly.
  6. let segmentedControl = MaterialSegmentedControl(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 30.0))
  7.  
  8. // Configure the view, note that you need to call updateViews in order to apply your cofiguration.
  9. segmentedControl.selectorColor = .black
  10. segmentedControl.selectorTextColor = .black
  11. setSampleSegments(segmentedControl, 18.0)
  12. segmentedControl.updateViews()
  13.  
  14. self.view.addSubview(segmentedControl)
  15. segmentedControl.translatesAutoresizingMaskIntoConstraints = false
  16. }
  17.  
  18. /**
  19. Create sample segments for the segmented control.
  20.  
  21. - Parameter segmentedControl: The segmented control to put these segments into.
  22. - Parameter cornerRadius: The corner radius to be set to segments and selectors.
  23. */
  24. private func setSampleSegments(_ segmentedControl: MaterialSegmentedControl, _ cornerRadius: CGFloat) {
  25. for i in 0..<3 {
  26. // Button background needs to be clear, it will be set to clear in segmented control anyway.
  27. let button = MaterialButton(text: "Segment \(i)", textColor: .gray, bgColor: .clear, cornerRadius: cornerRadius)
  28. segmentedControl.segments.append(button)
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement