In iPhone SDK, there is no setBackgroundImage function for setting an background image of an UIView. But actually, this can be done by the setBackgroundColor function. The following code will set the background view to Red.
1 | self .view.backgroundColor = [UIColor redColor]; |
So if you want to set a picture as an background image of a view, just initialize an UIColorinstance with an image and set it to the view.
1 | UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed: @"anImage.png" ]]; |
2 | self .view.backgroundColor = background; |
Please note that you have to set all the items which are in front of the background view toclearColor such that they will not cover the background image.
No comments:
Post a Comment