Question

I'm trying to create a picker controller with a 'Done' button positioned just above it, to display over a form that is in another view.

I have created a sub-class of UIViewController and using IB I've added a toolbar and a picker view. This seems fine and by copying the examples in UICatalog I can get it to display the required values and I can listen for selections etc.

alt text http://web.me.com/gareth.davis/so/settlement_picker_ui.png

In the above I have set the background color of the view to be alpha 0.0. I have also tried setting the alpha of the view it's self to 0.0, this just displays a completely transparent view.

alt text http://web.me.com/gareth.davis/so/picker_running_in_app.png

The above is the view controller displayed over the top of my form using:

    [self presentModalViewController:settlementPickerViewController                         
                        animated:YES];

In addition to trying to set various alpha properties of my view I have also attempted to change the height of the view in order such that there is no need for a transparent section, trouble is the view is then positioned half way up the screen.

Was it helpful?

Solution

The solution seems to be not to use a UIViewController instead a simple custom UIView does the job nicely.

I used Haentz's color setup in the awakeFromNib method:

- (void)awakeFromNib {
    picker.delegate = self;
    self.backgroundColor = [UIColor clearColor];    
}

Note that you have to implement this and not using the initWithFrame method that the x-code template gives you as nib controlled views don't use initWithFrame (from the apple documentation).

OTHER TIPS

Probably I just don't get it, but I don't exactly understand what's the problem here. In the bottom screenshot, should the UI elements be transparent, without the white area above? You need to set the frame of the UIView in your UIViewController appropriately and I guess you might have to set the background color transparent:

self.view.backgroundColor = [UIColor clearColor];

I'm not sure, since I never use the IB, but it may be possible to set the Alpha value of the background color of the base view to 0. Not the alpha of the view itself, but of the background color.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top