Azhar
Azhar

Reputation: 20670

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

enter image description here

Upvotes: 0

Views: 8543

Answers (2)

Ryan
Ryan

Reputation: 4884

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.

Upvotes: 0

Shamsudheen TK
Shamsudheen TK

Reputation: 31311

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

Upvotes: 3

Related Questions