Guest User

Untitled

a guest
Jun 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. var favoritesBarButtonOn: UIBarButtonItem!
  2. var favoritesBarButtonOFF: UIBarButtonItem!
  3.  
  4. favoritesBarButtonOn = UIBarButtonItem(image: #imageLiteral(resourceName: "TabBarIconSettingsOff"), style: .plain, target: self, action: #selector(didTapFavoritesBarButtonOn))
  5. favoritesBarButtonOFF = UIBarButtonItem(image: #imageLiteral(resourceName: "TabBarIconSettingsOn"), style: .plain, target: self, action: #selector(didTapFavoritesBarButtonOFF))
  6.  
  7. self.navigationItem.rightBarButtonItems = [self.rightNavBarButton, self.favoritesBarButtonOn]
  8.  
  9. func didTapFavoritesBarButtonOn() {
  10. self.navigationItem.setRightBarButtonItems([self.rightNavBarButton, self.favoritesBarButtonOFF], animated: false)
  11. print("Show Favorites")
  12. }
  13.  
  14. func didTapFavoritesBarButtonOFF() {
  15. self.navigationItem.setRightBarButtonItems([self.rightNavBarButton, self.favoritesBarButtonOn], animated: false)
  16. print("Show All Chat Rooms")
  17. }
  18.  
  19. favoritesBarButtonOn = UIBarButtonItem(image: #imageLiteral(resourceName: "TabBarIconSettingsOff"), style: .plain, target: self, action: #selector(didTapFavoritesBarButtonOn))
  20. favoritesBarButtonOFF = UIBarButtonItem(image: #imageLiteral(resourceName: "TabBarIconSettingsOn"), style: .plain, target: self, action: #selector(didTapFavoritesBarButtonOFF))
  21.  
  22. self.navigationItem.rightBarButtonItems = [self.favoritesBarButtonOn]
  23.  
  24. func didTapFavoritesBarButtonOn() {
  25. self.navigationItem.setRightBarButtonItems([self.favoritesBarButtonOFF], animated: false)
  26. print("Show Favorites")
  27. }
  28.  
  29. func didTapFavoritesBarButtonOFF() {
  30. self.navigationItem.setRightBarButtonItems([self.favoritesBarButtonOn], animated: false)
  31. print("Show All Chat Rooms")
  32. }
  33.  
  34. @IBOutlet weak var toolBar: UIToolbar!
  35. var pauseButton = UIBarButtonItem()
  36. var playButton = UIBarButtonItem()
  37. var arrayOfButtons = [AnyObject]()
  38.  
  39. override func viewDidLoad() {
  40. super.viewDidLoad()
  41. pauseButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Pause, target: self, action: "pauseButtonTapped")
  42. playButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: self, action: "playButtonTapped")
  43.  
  44. arrayOfButtons = self.toolBar.items!
  45. arrayOfButtons.insert(playButton, atIndex: 0) // change index to wherever you'd like the button
  46. self.toolBar.setItems(arrayOfButtons, animated: false)
  47. }
  48.  
  49. func playButtonTapped() {
  50. arrayOfButtons = self.toolBar.items!
  51. arrayOfButtons.removeAtIndex(0) // change index to correspond to where your button is
  52. arrayOfButtons.insert(pauseButton, atIndex: 0)
  53. self.toolBar.setItems(arrayOfButtons, animated: false)
  54. }
  55.  
  56. func pauseButtonTapped() {
  57. arrayOfButtons = self.toolBar.items!
  58. arrayOfButtons.removeAtIndex(0) // change index to correspond to where your button is
  59. arrayOfButtons.insert(playButton, atIndex: 0)
  60. self.toolBar.setItems(arrayOfButtons, animated: false)
  61. }
  62.  
  63. let playButton = UIButton(frame: CGRectMake(0, 0, 30, 30))
  64. playButton.addTarget(self, action: "togglePlay:", forControlEvents: .TouchUpInside)
  65. playButton.setImage(UIImage(named: "play-active"), forState: .Normal)
  66. playButton.setImage(UIImage(named: "play-inactive"), forState: .Selected)
  67. let rightButton = UIBarButtonItem(customView: playButton)
  68. self.navigationItem.setRightBarButtonItems([rightButton], animated: true)
Add Comment
Please, Sign In to add comment