iOS toolbar barbuttonitem spacer












-2














I am trying to add two bar buttons to toolbar in iOS [Cancel] & [Save] on right and left side accordingly.



I used a third bar button [Spacer] and set it to be [.flexiblewidth] Otherwise, when adding it only the left button appears [Cancel] and the [Spacer] & and [Save] which have to be next disappearing ?



the screen shot is in the link:
https://ibb.co/cZsaVV



let pickerView = UIPickerView()

override func viewDidLoad() {


pickerView.addSubview(self.setToolBar())
}

func setToolBar() -> UIToolbar {
let toolBar = UIToolbar()
toolBar.isTranslucent = true
toolBar.backgroundColor = UIColor.clear
let barButtonAttr = [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15),
NSAttributedString.Key.foregroundColor : UIColor.black]
// [Save] BarButtonItem
let saveBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.save, target: self, action: nil)
saveBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// [Cancel] BarButtonItem
let cancelBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel, target: self, action: nil)
cancelBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)

let spacerBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace ,
target: self, action: nil)
spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// add BarButtonItems to toolBar
toolBar.items = [cancelBarButtonItem,spacerBarButtonItem,saveBarButtonItem]
toolBar.sizeToFit()
return toolBar
}









share|improve this question
























  • Welcome to SO. Please add the screenshot to the post itself. Also: what happens, and what do you expect to happen? Try adding constraints to the toolbar to give a width of the screen
    – Daniel Springer
    Nov 23 at 6:11












  • here is the screen shot in the link: ibb.co/cZsaVV
    – Hadi AlNehlawi
    Nov 23 at 6:22










  • At the end of the post it says "enter image description here". Add a new line for that so the image is visible in the post.
    – Daniel Springer
    Nov 23 at 6:24










  • try to add two bar button item to UIToolBar and set to far right & and far left. They have been added next to each other on the left side?
    – Hadi AlNehlawi
    Nov 23 at 6:24












  • Try removing spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
    – Daniel Springer
    Nov 23 at 6:26
















-2














I am trying to add two bar buttons to toolbar in iOS [Cancel] & [Save] on right and left side accordingly.



I used a third bar button [Spacer] and set it to be [.flexiblewidth] Otherwise, when adding it only the left button appears [Cancel] and the [Spacer] & and [Save] which have to be next disappearing ?



the screen shot is in the link:
https://ibb.co/cZsaVV



let pickerView = UIPickerView()

override func viewDidLoad() {


pickerView.addSubview(self.setToolBar())
}

func setToolBar() -> UIToolbar {
let toolBar = UIToolbar()
toolBar.isTranslucent = true
toolBar.backgroundColor = UIColor.clear
let barButtonAttr = [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15),
NSAttributedString.Key.foregroundColor : UIColor.black]
// [Save] BarButtonItem
let saveBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.save, target: self, action: nil)
saveBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// [Cancel] BarButtonItem
let cancelBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel, target: self, action: nil)
cancelBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)

let spacerBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace ,
target: self, action: nil)
spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// add BarButtonItems to toolBar
toolBar.items = [cancelBarButtonItem,spacerBarButtonItem,saveBarButtonItem]
toolBar.sizeToFit()
return toolBar
}









share|improve this question
























  • Welcome to SO. Please add the screenshot to the post itself. Also: what happens, and what do you expect to happen? Try adding constraints to the toolbar to give a width of the screen
    – Daniel Springer
    Nov 23 at 6:11












  • here is the screen shot in the link: ibb.co/cZsaVV
    – Hadi AlNehlawi
    Nov 23 at 6:22










  • At the end of the post it says "enter image description here". Add a new line for that so the image is visible in the post.
    – Daniel Springer
    Nov 23 at 6:24










  • try to add two bar button item to UIToolBar and set to far right & and far left. They have been added next to each other on the left side?
    – Hadi AlNehlawi
    Nov 23 at 6:24












  • Try removing spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
    – Daniel Springer
    Nov 23 at 6:26














-2












-2








-2







I am trying to add two bar buttons to toolbar in iOS [Cancel] & [Save] on right and left side accordingly.



I used a third bar button [Spacer] and set it to be [.flexiblewidth] Otherwise, when adding it only the left button appears [Cancel] and the [Spacer] & and [Save] which have to be next disappearing ?



the screen shot is in the link:
https://ibb.co/cZsaVV



let pickerView = UIPickerView()

override func viewDidLoad() {


pickerView.addSubview(self.setToolBar())
}

func setToolBar() -> UIToolbar {
let toolBar = UIToolbar()
toolBar.isTranslucent = true
toolBar.backgroundColor = UIColor.clear
let barButtonAttr = [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15),
NSAttributedString.Key.foregroundColor : UIColor.black]
// [Save] BarButtonItem
let saveBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.save, target: self, action: nil)
saveBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// [Cancel] BarButtonItem
let cancelBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel, target: self, action: nil)
cancelBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)

let spacerBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace ,
target: self, action: nil)
spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// add BarButtonItems to toolBar
toolBar.items = [cancelBarButtonItem,spacerBarButtonItem,saveBarButtonItem]
toolBar.sizeToFit()
return toolBar
}









share|improve this question















I am trying to add two bar buttons to toolbar in iOS [Cancel] & [Save] on right and left side accordingly.



I used a third bar button [Spacer] and set it to be [.flexiblewidth] Otherwise, when adding it only the left button appears [Cancel] and the [Spacer] & and [Save] which have to be next disappearing ?



the screen shot is in the link:
https://ibb.co/cZsaVV



let pickerView = UIPickerView()

override func viewDidLoad() {


pickerView.addSubview(self.setToolBar())
}

func setToolBar() -> UIToolbar {
let toolBar = UIToolbar()
toolBar.isTranslucent = true
toolBar.backgroundColor = UIColor.clear
let barButtonAttr = [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15),
NSAttributedString.Key.foregroundColor : UIColor.black]
// [Save] BarButtonItem
let saveBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.save, target: self, action: nil)
saveBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// [Cancel] BarButtonItem
let cancelBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel, target: self, action: nil)
cancelBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)

let spacerBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace ,
target: self, action: nil)
spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
// add BarButtonItems to toolBar
toolBar.items = [cancelBarButtonItem,spacerBarButtonItem,saveBarButtonItem]
toolBar.sizeToFit()
return toolBar
}






ios iphone swift uibarbuttonitem uitoolbar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 6:35

























asked Nov 23 at 3:45









Hadi AlNehlawi

12




12












  • Welcome to SO. Please add the screenshot to the post itself. Also: what happens, and what do you expect to happen? Try adding constraints to the toolbar to give a width of the screen
    – Daniel Springer
    Nov 23 at 6:11












  • here is the screen shot in the link: ibb.co/cZsaVV
    – Hadi AlNehlawi
    Nov 23 at 6:22










  • At the end of the post it says "enter image description here". Add a new line for that so the image is visible in the post.
    – Daniel Springer
    Nov 23 at 6:24










  • try to add two bar button item to UIToolBar and set to far right & and far left. They have been added next to each other on the left side?
    – Hadi AlNehlawi
    Nov 23 at 6:24












  • Try removing spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
    – Daniel Springer
    Nov 23 at 6:26


















  • Welcome to SO. Please add the screenshot to the post itself. Also: what happens, and what do you expect to happen? Try adding constraints to the toolbar to give a width of the screen
    – Daniel Springer
    Nov 23 at 6:11












  • here is the screen shot in the link: ibb.co/cZsaVV
    – Hadi AlNehlawi
    Nov 23 at 6:22










  • At the end of the post it says "enter image description here". Add a new line for that so the image is visible in the post.
    – Daniel Springer
    Nov 23 at 6:24










  • try to add two bar button item to UIToolBar and set to far right & and far left. They have been added next to each other on the left side?
    – Hadi AlNehlawi
    Nov 23 at 6:24












  • Try removing spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
    – Daniel Springer
    Nov 23 at 6:26
















Welcome to SO. Please add the screenshot to the post itself. Also: what happens, and what do you expect to happen? Try adding constraints to the toolbar to give a width of the screen
– Daniel Springer
Nov 23 at 6:11






Welcome to SO. Please add the screenshot to the post itself. Also: what happens, and what do you expect to happen? Try adding constraints to the toolbar to give a width of the screen
– Daniel Springer
Nov 23 at 6:11














here is the screen shot in the link: ibb.co/cZsaVV
– Hadi AlNehlawi
Nov 23 at 6:22




here is the screen shot in the link: ibb.co/cZsaVV
– Hadi AlNehlawi
Nov 23 at 6:22












At the end of the post it says "enter image description here". Add a new line for that so the image is visible in the post.
– Daniel Springer
Nov 23 at 6:24




At the end of the post it says "enter image description here". Add a new line for that so the image is visible in the post.
– Daniel Springer
Nov 23 at 6:24












try to add two bar button item to UIToolBar and set to far right & and far left. They have been added next to each other on the left side?
– Hadi AlNehlawi
Nov 23 at 6:24






try to add two bar button item to UIToolBar and set to far right & and far left. They have been added next to each other on the left side?
– Hadi AlNehlawi
Nov 23 at 6:24














Try removing spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
– Daniel Springer
Nov 23 at 6:26




Try removing spacerBarButtonItem.setTitleTextAttributes(barButtonAttr, for: .normal)
– Daniel Springer
Nov 23 at 6:26












2 Answers
2






active

oldest

votes


















0














func createAccessoryViewWithTarget(_ target: AnyObject, width: CGFloat) -> UIView {

// Previous button
let previousButton = UIBarButtonItem(title: "Previous", style: .plain, target: target, action: #selector(self.moveToPreviousTextField))
previousButton.tintColor = UIColor.white

//Next button
let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: target, action: #selector(self.moveToNextTextField))
nextButton.tintColor = UIColor.white

// Dismiss/close/done button
let doneButton = UIBarButtonItem(title: "Done", style: .done, target: target, action: #selector(self.keyboardDoneButtonTapped))
doneButton.tintColor = UIColor.white

let keyboardToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 44))
keyboardToolbar.barStyle = .black

let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let fixedSpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)

var itemsArray = [UIBarButtonItem]()
itemsArray.append(previousButton)
itemsArray.append(fixedSpace)
itemsArray.append(nextButton)
itemsArray.append(flexSpace)
itemsArray.append(doneButton)
keyboardToolbar.items = itemsArray
keyboardToolbar.sizeToFit()

return keyboardToolbar
}


This one is old code may be swift3 I guess. Here Im adding 3 buttons previous next and done button. flexible space and fixed space are used for spaces between buttons. Important to note here is the order that you adding your barbutton items. In your case use flexible space to place your 2 buttons on right and left end in the order of left end button, flexible space, right end button.






share|improve this answer





























    0














    I've got the solution finally.



    I am adding the ToolBar to the PickerView and then calling UIToolBar.SizeToFit() which is must in all cases.



    the issue was I had to change the picker view size later in this case the size of subview ToolBar is not adapting with the new size coordination of pickerView. So the solution simply to call again ToolBar.SizeToFit() after any modification of parent view. here's snap of the code:



    // popupView is custom UIPickerView



    popupView.frame = CGRect(x:0, y:0, width:100, height:100)



    // toolBar is an object of UIToolBar of the custom UIPickerView AddCurrencyPicker



    (popupView as! AddCurrencyPicker).toolBar.sizeToFit()






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440419%2fios-toolbar-barbuttonitem-spacer%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      func createAccessoryViewWithTarget(_ target: AnyObject, width: CGFloat) -> UIView {

      // Previous button
      let previousButton = UIBarButtonItem(title: "Previous", style: .plain, target: target, action: #selector(self.moveToPreviousTextField))
      previousButton.tintColor = UIColor.white

      //Next button
      let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: target, action: #selector(self.moveToNextTextField))
      nextButton.tintColor = UIColor.white

      // Dismiss/close/done button
      let doneButton = UIBarButtonItem(title: "Done", style: .done, target: target, action: #selector(self.keyboardDoneButtonTapped))
      doneButton.tintColor = UIColor.white

      let keyboardToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 44))
      keyboardToolbar.barStyle = .black

      let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
      let fixedSpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)

      var itemsArray = [UIBarButtonItem]()
      itemsArray.append(previousButton)
      itemsArray.append(fixedSpace)
      itemsArray.append(nextButton)
      itemsArray.append(flexSpace)
      itemsArray.append(doneButton)
      keyboardToolbar.items = itemsArray
      keyboardToolbar.sizeToFit()

      return keyboardToolbar
      }


      This one is old code may be swift3 I guess. Here Im adding 3 buttons previous next and done button. flexible space and fixed space are used for spaces between buttons. Important to note here is the order that you adding your barbutton items. In your case use flexible space to place your 2 buttons on right and left end in the order of left end button, flexible space, right end button.






      share|improve this answer


























        0














        func createAccessoryViewWithTarget(_ target: AnyObject, width: CGFloat) -> UIView {

        // Previous button
        let previousButton = UIBarButtonItem(title: "Previous", style: .plain, target: target, action: #selector(self.moveToPreviousTextField))
        previousButton.tintColor = UIColor.white

        //Next button
        let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: target, action: #selector(self.moveToNextTextField))
        nextButton.tintColor = UIColor.white

        // Dismiss/close/done button
        let doneButton = UIBarButtonItem(title: "Done", style: .done, target: target, action: #selector(self.keyboardDoneButtonTapped))
        doneButton.tintColor = UIColor.white

        let keyboardToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 44))
        keyboardToolbar.barStyle = .black

        let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
        let fixedSpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)

        var itemsArray = [UIBarButtonItem]()
        itemsArray.append(previousButton)
        itemsArray.append(fixedSpace)
        itemsArray.append(nextButton)
        itemsArray.append(flexSpace)
        itemsArray.append(doneButton)
        keyboardToolbar.items = itemsArray
        keyboardToolbar.sizeToFit()

        return keyboardToolbar
        }


        This one is old code may be swift3 I guess. Here Im adding 3 buttons previous next and done button. flexible space and fixed space are used for spaces between buttons. Important to note here is the order that you adding your barbutton items. In your case use flexible space to place your 2 buttons on right and left end in the order of left end button, flexible space, right end button.






        share|improve this answer
























          0












          0








          0






          func createAccessoryViewWithTarget(_ target: AnyObject, width: CGFloat) -> UIView {

          // Previous button
          let previousButton = UIBarButtonItem(title: "Previous", style: .plain, target: target, action: #selector(self.moveToPreviousTextField))
          previousButton.tintColor = UIColor.white

          //Next button
          let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: target, action: #selector(self.moveToNextTextField))
          nextButton.tintColor = UIColor.white

          // Dismiss/close/done button
          let doneButton = UIBarButtonItem(title: "Done", style: .done, target: target, action: #selector(self.keyboardDoneButtonTapped))
          doneButton.tintColor = UIColor.white

          let keyboardToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 44))
          keyboardToolbar.barStyle = .black

          let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
          let fixedSpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)

          var itemsArray = [UIBarButtonItem]()
          itemsArray.append(previousButton)
          itemsArray.append(fixedSpace)
          itemsArray.append(nextButton)
          itemsArray.append(flexSpace)
          itemsArray.append(doneButton)
          keyboardToolbar.items = itemsArray
          keyboardToolbar.sizeToFit()

          return keyboardToolbar
          }


          This one is old code may be swift3 I guess. Here Im adding 3 buttons previous next and done button. flexible space and fixed space are used for spaces between buttons. Important to note here is the order that you adding your barbutton items. In your case use flexible space to place your 2 buttons on right and left end in the order of left end button, flexible space, right end button.






          share|improve this answer












          func createAccessoryViewWithTarget(_ target: AnyObject, width: CGFloat) -> UIView {

          // Previous button
          let previousButton = UIBarButtonItem(title: "Previous", style: .plain, target: target, action: #selector(self.moveToPreviousTextField))
          previousButton.tintColor = UIColor.white

          //Next button
          let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: target, action: #selector(self.moveToNextTextField))
          nextButton.tintColor = UIColor.white

          // Dismiss/close/done button
          let doneButton = UIBarButtonItem(title: "Done", style: .done, target: target, action: #selector(self.keyboardDoneButtonTapped))
          doneButton.tintColor = UIColor.white

          let keyboardToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 44))
          keyboardToolbar.barStyle = .black

          let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
          let fixedSpace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)

          var itemsArray = [UIBarButtonItem]()
          itemsArray.append(previousButton)
          itemsArray.append(fixedSpace)
          itemsArray.append(nextButton)
          itemsArray.append(flexSpace)
          itemsArray.append(doneButton)
          keyboardToolbar.items = itemsArray
          keyboardToolbar.sizeToFit()

          return keyboardToolbar
          }


          This one is old code may be swift3 I guess. Here Im adding 3 buttons previous next and done button. flexible space and fixed space are used for spaces between buttons. Important to note here is the order that you adding your barbutton items. In your case use flexible space to place your 2 buttons on right and left end in the order of left end button, flexible space, right end button.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 at 11:53









          Sarath

          95110




          95110

























              0














              I've got the solution finally.



              I am adding the ToolBar to the PickerView and then calling UIToolBar.SizeToFit() which is must in all cases.



              the issue was I had to change the picker view size later in this case the size of subview ToolBar is not adapting with the new size coordination of pickerView. So the solution simply to call again ToolBar.SizeToFit() after any modification of parent view. here's snap of the code:



              // popupView is custom UIPickerView



              popupView.frame = CGRect(x:0, y:0, width:100, height:100)



              // toolBar is an object of UIToolBar of the custom UIPickerView AddCurrencyPicker



              (popupView as! AddCurrencyPicker).toolBar.sizeToFit()






              share|improve this answer


























                0














                I've got the solution finally.



                I am adding the ToolBar to the PickerView and then calling UIToolBar.SizeToFit() which is must in all cases.



                the issue was I had to change the picker view size later in this case the size of subview ToolBar is not adapting with the new size coordination of pickerView. So the solution simply to call again ToolBar.SizeToFit() after any modification of parent view. here's snap of the code:



                // popupView is custom UIPickerView



                popupView.frame = CGRect(x:0, y:0, width:100, height:100)



                // toolBar is an object of UIToolBar of the custom UIPickerView AddCurrencyPicker



                (popupView as! AddCurrencyPicker).toolBar.sizeToFit()






                share|improve this answer
























                  0












                  0








                  0






                  I've got the solution finally.



                  I am adding the ToolBar to the PickerView and then calling UIToolBar.SizeToFit() which is must in all cases.



                  the issue was I had to change the picker view size later in this case the size of subview ToolBar is not adapting with the new size coordination of pickerView. So the solution simply to call again ToolBar.SizeToFit() after any modification of parent view. here's snap of the code:



                  // popupView is custom UIPickerView



                  popupView.frame = CGRect(x:0, y:0, width:100, height:100)



                  // toolBar is an object of UIToolBar of the custom UIPickerView AddCurrencyPicker



                  (popupView as! AddCurrencyPicker).toolBar.sizeToFit()






                  share|improve this answer












                  I've got the solution finally.



                  I am adding the ToolBar to the PickerView and then calling UIToolBar.SizeToFit() which is must in all cases.



                  the issue was I had to change the picker view size later in this case the size of subview ToolBar is not adapting with the new size coordination of pickerView. So the solution simply to call again ToolBar.SizeToFit() after any modification of parent view. here's snap of the code:



                  // popupView is custom UIPickerView



                  popupView.frame = CGRect(x:0, y:0, width:100, height:100)



                  // toolBar is an object of UIToolBar of the custom UIPickerView AddCurrencyPicker



                  (popupView as! AddCurrencyPicker).toolBar.sizeToFit()







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 at 18:28









                  Hadi AlNehlawi

                  12




                  12






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440419%2fios-toolbar-barbuttonitem-spacer%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                      Calculate evaluation metrics using cross_val_predict sklearn

                      Insert data from modal to MySQL (multiple modal on website)