简体   繁体   中英

ios to create view programmatically

I am trying to create a view like the below one programmatically but it covers the whole screen and does not be like this. There could be some thing size = Freeform , but could not find code on google to handle this.

UIView *picker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260)];
    picker.backgroundColor = [UIColor whiteColor];

Actually I want to create this whole view programmatically not though interface Builder.

please help

在此处输入图片说明

No other way than CGRectMake

if you want create the UIView that covers the whole screen

UIView *picker = [[UIView alloc] initWithFrame:self.view.bounds];
picker.backgroundColor=[UIColor blueColor];
[self.view addSubview: picker];

if you want create the UIView that not covers the whole screen

UIView *picker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 260)];
picker.backgroundColor=[UIColor blueColor];
[self.view addSubview: picker];

Create UIToolBar which has UIBarButtonItem(=Done). Set the UIToolBar as UIDatePicker's inputAccessoryView.

You don't even need a backgroundView to add Done button and date picker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM