1

I would like to add two UIButtons in the UIPickerView (on bottom of it). Please take a look at the Cancel and Done buttons in this image:

enter image description here

Here My code Upload:-

class DatePicker{

var containerView = UIView()
var datePicker = UIView()
var datePickerView = UIDatePicker()
var toolBar = UIToolbar()
internal class var shared: DatePicker {
    struct Static {
        static let instance: DatePicker = DatePicker()
    }
    return Static.instance
}
internal func showProgressView(view: UIView) {
    containerView.frame = view.frame
    containerView.center = view.center
    containerView.backgroundColor = UIColor(hex: 0xffffff, alpha: 0.3)
    datePickerView.datePickerMode = .Date
    datePicker.frame = CGRectMake(0, 0, 250, 250)
    datePicker.center = view.center
    datePicker.backgroundColor = UIColor(hex: 0x444444, alpha: 0.7)
    datePicker.clipsToBounds = true
    datePicker.layer.cornerRadius = 10
    datePickerView.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
    datePickerView.frame = CGRectMake(0, 0, 250, 250)
    datePicker.addSubview(datePickerView)
    containerView.addSubview(datePicker)
    view.addSubview(containerView)
}
internal func hideProgressView() {
    containerView.removeFromSuperview()
}

}

How can i get UIToolbar And Two Button?

iParesh
  • 2,338
  • 1
  • 18
  • 30

1 Answers1

0

I would recommend making a .xib with the toolbar and picker view in it. Put two bar buttons on the bar and put a bar button spacer in between them.

Link on how to use a xib

You can make the animation of it appearing look great if you start its frame off screen and use this function to move it on screen.

UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: {
        if viewToMove != nil {
            viewToMove!.frame.origin.y/*orX*/ = onScreenPosition
        } else {
            "sidePanel == nil"
        }
}, completion: completion)

usingSpringWithDamping can be set to 1 if you don't want any bounce in animation. If this is for an iPhone, i would recommend making the initial frame equal to something like

CGRectMake(0, UIScreen.mainScreen().bounds.height, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height/2)

and then the view to move line would become

viewToMove!.frame.origin.y = UIScreen.mainScreen().bounds.height/2

using the previous function to bring it on screen and

viewToMove!.frame.origin.y = UIScreen.mainScreen().bounds.height

to move it off screen. You can access the buttons of the xib in a few different ways, but I recommend using a delegate.

Here is a guide to them.

If you are not familiar with them, I would become familiar, because they are very useful! If you have any questions don't hesitate to ask!

Community
  • 1
  • 1
Sethmr
  • 3,046
  • 1
  • 24
  • 42