Search code examples
iosobjective-cuiviewuiimagepresentviewcontroller

Present transparent UIView with opaque UIButton or UIImage


I am trying to make a transparent UIView when using presentViewController. The problem is that the UIButton or UIImageView always are transparent, how can I make them non-transparent?

targetViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"newViewController"];

targetViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;

[self presentViewController:targetViewController animated:YES completion:nil];

result: https://i.sstatic.net/YJjBv.png

I want UIButton or UIImageView to be opaque. How can I do it?


Solution

  • Instead of using UIView's alpha, using clear backgroundColor

    targetViewController.view.backgroundColor = [UIColor clearColor];