Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
kayeetong
84 PointsSimple - How to change attributes of UIDatePicker in ViewController when linked to UITextField?
I want to change the attributes of UIDatePicker such as minuteInterval = 15
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var dateTextField: UITextField!
var datePicker:UIDatePicker!
override func viewDidLoad()
{
var customView:UIView = UIView (frame: CGRectMake(0, 100, 320, 160));
datePicker = UIDatePicker(frame: CGRectMake(0, 0, 320, 160));
customView .addSubview(datePicker);
dateTextField.inputView = customView;
var doneButton:UIButton = UIButton (frame: CGRectMake(100, 100, 100, 44));
doneButton.setTitle("Done", forState: UIControlState.Normal)
doneButton.addTarget(self, action: "datePickerSelected", forControlEvents: UIControlEvents.TouchUpInside);
doneButton.backgroundColor = UIColor.grayColor();
dateTextField.inputAccessoryView = doneButton;
}
func datePickerSelected()
{
dateTextField.text = datePicker.date.description;
}
}