1

From past few days i am trying to generate a popover for programmatically added UIBarButtonItem but i couldn't succeed. Added to this, i even want this popover to be presented with few images sequentially which are clickable. The following is the code of how i generated a UIBarButtonItem programmatically

func imagerendering(){
    let barbuttonimage = UIImage(named: "app")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    let button1 = UIBarButtonItem(image: barbuttonimage, style: .Plain, target: self, action: nil)
    self.navigationItem.leftBarButtonItem = button1

    let attachButtonImage = UIImage(named: "icon-Attach")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    let attachButton = UIBarButtonItem(image: attachButtonImage, style: UIBarButtonItemStyle.Plain, target: self, action: nil)
    self.navigationItem.setRightBarButtonItems([menuButton,attachButton], animated: true)

    let fixedSpace:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
    fixedSpace.width = 5.0
    self.navigationItem.rightBarButtonItems = [menuButton, fixedSpace, attachButton]
    self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName:UIFont(name: "Avenir-Black", size: 16)!]
}

I have presented my desired output in an image as a link below. please go through it and let me know whether what i am desiring is possible or not.

desired output image

arun_K
  • 313
  • 1
  • 4
  • 12
  • Yes it is possible. Tell me are you able to do a simple popover? – iRiziya Sep 11 '15 at 13:22
  • @iRealMe i know how to present it using storyboard but programmatically i am not sure.. have you gone through the image...? within the popover i need to present images sequentially and these images in-turn will have a action to perform – arun_K Sep 11 '15 at 13:30
  • Ok..and from where those image will come? – iRiziya Sep 11 '15 at 13:33
  • just like in tableview we can add images right .. and program it. In the same way i want to do it please go through the link [example image] (http://s16.postimg.org/4zri7xc6d/exampleimage.png ) – arun_K Sep 11 '15 at 13:55

2 Answers2

1

To add an extra bar item on navigation bar using storyboard, you can refer these answers

After that, set a popover from storyboard(you know it well as you said) and then put required buttons with actions in your popop view. You can set image for a button instead of title text.

Community
  • 1
  • 1
iRiziya
  • 3,235
  • 1
  • 22
  • 36
  • 1
    as mentioned earlier this UIBarButtonItem has been created programmatically there is no instance in the story board – arun_K Sep 11 '15 at 13:57
  • Oh ok. Once I tried to popup programmatically but I could not. So all you have to try is a popup from the code only then rest of things can be proceed – iRiziya Sep 11 '15 at 13:59
  • There may be alternate ways, if you try to find it – iRiziya Sep 11 '15 at 14:01
  • here is a sample of my storyboard.. [storyboard image] (http://s1.postimg.org/neiwsgzb3/storyboard.png) go through it and let me know how should i proceed further – arun_K Sep 11 '15 at 14:07
  • Ah,why are you creating your bar button from the code only? – iRiziya Sep 11 '15 at 14:09
  • Yes I am getting your problem but tell me is it compulsory to create it from code? – iRiziya Sep 11 '15 at 14:11
  • I have created it because I am unable to add another barbutton to the navigation bar. ... if at all I am adding it it's just replacing the other one.... – arun_K Sep 11 '15 at 14:27
  • There are solutions of it..you may try! see the answers here http://stackoverflow.com/a/20419513/3734028 – iRiziya Sep 11 '15 at 15:35
  • that done the trick i have gone through the first one in the link – arun_K Sep 12 '15 at 17:17
  • I have edited my answer for that useful link, please upvote! – iRiziya Sep 14 '15 at 04:48
  • sorry i can't upvote it as i don't have enough reputation.... i haven't got a clue of upvoting of another answer – arun_K Sep 14 '15 at 05:01
  • How come this is the accepted answer? The question explicitly say that the button is added programatically, yet the accepted answer says how to solve the problem using storyboard. – mortadelo Mar 31 '16 at 08:17
1

Look into the WYPopoverController library. It gives you the functionality you're looking for.

BenJammin
  • 1,479
  • 13
  • 18
  • thank you... for your response i achieved it through this link (http://stackoverflow.com/questions/9897978/cant-assign-multiple-buttons-to-uinavigationitem-when-using-storyboard-with-ios/20419513#20419513) – arun_K Sep 12 '15 at 17:15