There is an additional pane with buttons appears in messages app on iPhone when tapping Edit button. See link, screenshot.
Messages app on iPhone
Is it a default UITableView property? (Probably not)
Is it a UIView, showing over tableView with delegate methods for handling buttons actions?
I searched everywhere with no luck. Can you give me the cue, how I can make the same one myself?
My app is written in Swift.
It's probably a UIToolbar. Just add it at the bottom of your viewcontroller's view.
Thanks to all, you were right, it is a UIToolbar, and it is quite easy to use.
To create toolbar:
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 50))
toolbar.barStyle = UIBarStyle.default
toolbar.items = [
UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(cancelAction)),
UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil),
UIBarButtonItem(title: "Next", style: UIBarButtonItemStyle.plain, target: self, action: #selector(nextAction))]
toolbar.sizeToFit()
To show it:
view.addSubview(toolbar)
To remove it:
toolbar.removeFromSuperView
Related
Twitter Registration Page
Hi everyone I have some cushions about UItoolBar on swift 3/4
I'm trying to make an singIn design like twitter,
1) i create toolbar with code;
let toolBar = UIToolbar()
toolBar.sizeToFit()
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(self.doneClicked))
toolBar.setItems([flexibleSpace, doneButton], animated: false)
kullaniciAdi.inputAccessoryView = toolBar
eposta.inputAccessoryView = toolBar
sifre.inputAccessoryView = toolBar
but I can't add custom buttons on that. Like changing the "Done" text in my language.
2) So I created manually using Storyboard a toolBar with inside a button and Flexible Space. But ı need to "attach" that toolbar to the keyboard, so when i start to edit the textfield the toolbar will automatically show up. NOTE: it will be fantastic if the toolbar will show too when not-editing textField. Like that:
My app trying too attach toolbar
THANK YOU ALL
In Code
let sonrakiButton = UIBarButtonItem(title: "Sonraki", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.sendDoneBtnAction))
For more info, read this link
I am new to iOS (swift) programming. I am creating my first stop watch application. I have added a navigationBar to the MainStoryBoard, and then two navigation items on the bar, one on the left and one on the right. I would like to change the text of left navigation item in the viewDidLoad method and then in an IBAction. Can anyone help me please.
With my .NET coding intellect, I created IBOutlets for each of them and then tried changing their title properties but have failed.
Another similar question regarding the same is how can I toggle the icons on navigation items programmatically.
For UIBarButtonItem with custom button image:
let btnName = UIButton()
btnName.setImage(UIImage(named: "imagename"), forState: .Normal)
btnName.frame = CGRectMake(0, 0, 30, 30)
btnName.addTarget(self, action: Selector("action"), forControlEvents: .TouchUpInside)
Set Right/Left Bar Button item:
let rightBarButton = UIBarButtonItem()
rightBarButton.customView = btnName
self.navigationItem.rightBarButtonItem = rightBarButton
For System UIBarButtonItem:
let camera = UIBarButtonItem(barButtonSystemItem: .Camera, target: self, action: Selector("btnOpenCamera"))
self.navigationItem.rightBarButtonItem = camera
You should don't create UINavigationBar on StoryBoard. You should ember it into UINavigationController. And in viewDidLoad you can add NavigationItem programmatically.
Add NavigationBarItem just with text:
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "left", style: .Done, target: self, action: "leftTap")
With Image:
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "backIcon#3x"), style: .Done, target: self, action: "rightTap")
And in Action you can change text or image:
self.navigationItem.leftBarButtonItem?.title = "left change"
self.navigationItem.rightBarButtonItem?.image = UIImage(named: "calendar-icons#3x")
With title and image above just is demo. You can reference to my demo code: Demo Change NavigationItem Programmatically
Hop this help!
I want it so that my navBar doesn't sit on top of my table view but instead is separate from it, so each tableView cell is displayed in equal proportions. As it is, I can't seem to change it, I have tried adding it manually, programtically and tried to change it in the view hierarchy, which I am unable to do. I imagine there is a straightforward solution to this I just can't work out what that is? Below is my code.
override func viewDidLoad() {
super.viewDidLoad()
let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, self.view.frame.size.width, 44))
navigationBar.backgroundColor = UIColor.whiteColor()
navigationBar.delegate = self
let navigationItem = UINavigationItem()
navigationItem.title = "Title"
let leftButton = UIBarButtonItem(title: "Save", style: UIBarButtonItemStyle.Plain, target: self, action: "btn_clicked:")
let rightButton = UIBarButtonItem(title: "Right", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
navigationItem.leftBarButtonItem = leftButton
navigationItem.rightBarButtonItem = rightButton
navigationBar.items = [navigationItem]
self.view.addSubview(navigationBar)
}
I had the same problem. A solution is just using a standard view controller and then adding table view and navBag. Instead of trying to add a navBar on top of a tableviewcontroller.
Im quite new to swift but i hope this answer helps.
I'm running across this issue which I can't seem to find the answer to online. Basically what I'm trying to do is programmatically create a UIToolbar with some UIBarButtonItems.
What I've done (as detailed below) is create the UIToolbar and then set the items of the UIToolbar to an array holding all the UIBarButtonItems I want.
Unfortunately, though the UIToolbar shows up, the UIBarButtonItems have yet to show themselves
Any suggestions or explanations as to why this is happening is much appreciated!
class DrawViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//create bar buttons
let deleteBarButton = UIBarButtonItem(image: UIImage(named: "greyDelete"), style: .Plain, target: self, action: "deleteView:")
let eraseBarButton = UIBarButtonItem(image: UIImage(named: "greyErase"), style: .Plain, target: self, action: "erase:")
let resizeBarButton = UIBarButtonItem(image: UIImage(named: "greyResize"), style: .Plain, target: self, action: "resize:")
let viewBarButton = UIBarButtonItem(image: UIImage(named: "greyView"), style: .Plain, target: self, action: "view:")
let colorBarButton = UIBarButtonItem(image: UIImage(named: "greyColor"), style: .Plain, target: self, action: "color:")
let drawBarButton = UIBarButtonItem(image: UIImage(named: "greyDraw"), style: .Plain, target: self, action: "draw:")
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil)
//set up toolbar
let toolbarItems = [deleteBarButton, flexibleSpace, eraseBarButton,
flexibleSpace, resizeBarButton, flexibleSpace,
viewBarButton, flexibleSpace, colorBarButton,
flexibleSpace, drawBarButton]
let toolbar = UIToolbar(frame: CGRectMake(0, view.bounds.height*0.93, view.bounds.width, view.bounds.height*0.7))
toolbar.barTintColor = UIColor(patternImage: UIImage(named: "blueToolbar")!)
toolbar.setItems(toolbarItems, animated: true)
self.view.addSubview(toolbar)
}
As you can see only the toolbar show up
And the image names (of the images used to create the UIBarButtons) are the same names as those in the Assets catalog
I would imagine the problem is the curious way you're creating the UIToolbar. This line here seems deeply suspect:
let toolbar = UIToolbar(frame: CGRectMake(0, view.bounds.height*0.93, view.bounds.width, view.bounds.height*0.7))
Why make it 0.7 times the height of your view?
To fix this problem, create the toolbar either without the frame constructor or with CGRectZero for its frame. Then use sizeToFit() to make it the appropriate size.
A simpler alternative, if possible, is to use a UINavigationController and tell it to show its own toolbar. You can then fill that by setting your view controller's toolbarItems property to your array, and it will all work without you having to create, position or manage a UIToolbar at all.
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
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.
Look into the WYPopoverController library. It gives you the functionality you're looking for.