Setting frame to Date picker in iOS7

后端 未结 1 621
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 19:43

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 e

1条回答
  •  孤街浪徒
    2021-01-16 20:12

    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];
    

    0 讨论(0)
提交回复
热议问题