xcode - Swift - Horizontal Bar under selected button -


i want add white horizontal bar under selected button on menu. youtube app. this menu

abd youtube

i searched info couldnt find this. , code. thanks

import uikit  class tabviewcontroller: uiviewcontroller {       @iboutlet var contentview: uiview!     @iboutlet var buttons: [uibutton]!      var rifleviewcontroller: uiviewcontroller!     var pistolviewcontroller: uiviewcontroller!     var shotgunviewcontroller: uiviewcontroller!     var smgsviewcontroller: uiviewcontroller!     var sniperviewcontroller: uiviewcontroller!      var viewcontrollers: [uiviewcontroller]!     var selectedindex: int = 0      override func viewdidload() {         super.viewdidload()          let storyboard = uistoryboard(name: "main", bundle: nil)          rifleviewcontroller = storyboard.instantiateviewcontroller(withidentifier: "rifles")         sniperviewcontroller = storyboard.instantiateviewcontroller(withidentifier: "snipers")         smgsviewcontroller = storyboard.instantiateviewcontroller(withidentifier: "smgss")         shotgunviewcontroller = storyboard.instantiateviewcontroller(withidentifier: "shotguns")         pistolviewcontroller = storyboard.instantiateviewcontroller(withidentifier: "pistols")         viewcontrollers = [rifleviewcontroller,                            pistolviewcontroller,                            shotgunviewcontroller,                            smgsviewcontroller,                            sniperviewcontroller]          buttons[selectedindex].isselected = true         didpresstab(buttons[selectedindex])       }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }       @ibaction func didpresstab(_ sender: uibutton) {          let previousindex = selectedindex          selectedindex = sender.tag          buttons[previousindex].isselected = false         let previousvc = viewcontrollers[previousindex]          previousvc.willmove(toparentviewcontroller: nil)         previousvc.view.removefromsuperview()         previousvc.removefromparentviewcontroller()          sender.isselected = true          let vc = viewcontrollers[selectedindex]          addchildviewcontroller(vc)          vc.view.frame = contentview.bounds         contentview.addsubview(vc.view)         vc.didmove(toparentviewcontroller: self)         }  } 

you achieve of simple animation. in example - app, added view @ top of screen in storyboard , put 4 buttons on top of it. connected buttons function called "buttontapped" (important: need include sender here). code simple:

class viewcontroller: uiviewcontroller {  @iboutlet weak var backgroundview: uiview! var movingview = uiview()  override func viewdidload() {     super.viewdidload()      let screenwidth = uiscreen.main.bounds.width      movingview = uiview(frame: cgrect(x: 0, y: 55, width: screenwidth / 4, height: 5))     movingview.backgroundcolor = uicolor.white   //if backgroundview's color black     backgroundview.addsubview(movingview) }   @ibaction func buttontapped(_ sender: uibutton) {     let newx = sender.frame.origin.x      uiview.animate(withduration: 1) {         self.movingview.frame.origin.x = newx     } } } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -