Setting frame to Date picker in iOS7

a 夏天 提交于 2019-12-01 13:47:13

问题


I am able to set date picker frame from Storyboard. But I am not able to set the frame programatically. I would like to no why datePicker.frame is not working even though setFrame: functionality is not deprecated in iOS7. Also please provide a way to set date picker frame programatically. Any help is greatly appreciated.


回答1:


If you have already added UIDatePicker to .nib or .storyboard file and would like to update frame programatically, then you can update frame inside viewDidLayoutSubviews method in your view controller. I just tried to update frame and it worked on iOS 7.0

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    self.datePicker.frame = CGRectMake(0, 50, 300, 162);
}

If want to add a date picker programatically in view controller then you can try creating a date picker in viewDidLoad method and add it to subview.

UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 300, 300, 162)];
[self.view addSubview:datePicker];


来源:https://stackoverflow.com/questions/19513007/setting-frame-to-date-picker-in-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!