I managed to successfully change some of my UIView background to a custom image using
self.view.backgroundColor = 开发者_如何学JAVA[UIColor colorWithPatternImage:[UIImage imageNamed:@"myCustomBackground.jpg"]];
But it does not work on a particular view in a controller that is presented modally as such,
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
navController.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:navController animated:NO];
[loginViewController release];
[navController release];
It seems like self.view
inside this controller is behind the view it was showing.
EDIT
LoginViewController.m
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myCustomBackground.jpg"]];
}
self.view in this case seems to be hidden behind the current view that it's displaying. I did not add any subView beforehand.
As you mentioned in your comments, your view contains UIScrollView
, UILabel
and UIButton
.
You should set to all this subviews property backgroundColor = [UIColor clearColor];
. Hopefully that would help.
If you are editing subview in IB then you should find property Background
in Attributes Inspector and select Clear Color
(for all subviews).
精彩评论