Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIView Background Image

Tags:

ios

uiview

I want to have a UIImageas a background image on a UIView.

Here is my code:

UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login.png"]]; self.view.backgroundColor = background; [background release]; 

The Problem is, that the scale is not okay. It scaled 640 to 480, so I can't tell it 100% sure but it looks like only 300 to 250 is displayed or something like that.

Is there a fit to scale / fit to UIView / fit to size modus?

like image 951
PassionateDeveloper Avatar asked Apr 03 '12 13:04

PassionateDeveloper


People also ask

How to set background Image for Uiview in swift?

Swift 5.3 in XCode 12.2 PlaygroundsSelect from the top-menu Editor->Insert Image Literal... and navigate to the file. Click Open . The file is added to a playground Resource folder and will then appear when the playground is run in whichever view it was positioned when selected.

How do you put a background picture on storyboard?

Go to 'View->Show Library' and choose the Image View and drag it to the middle of the screen until it snaps perfectly in the center. This Image View will serve as the background image and it will fill the entire screen, including the area past the safe area view.

How do I change the background color in programmatically in Swift?

Method 2 − Programmatically changing the backgroundCreate outlet of the button on the View Controller. In the viewDidLoad() or viewWillLayoutSubview() method add the code to change the background color.


1 Answers

you are required to process your image before you add it, try this :

UIGraphicsBeginImageContext(self.view.frame.size); [[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();  self.view.backgroundColor = [UIColor colorWithPatternImage:image]; 
like image 77
uneakharsh Avatar answered Sep 20 '22 00:09

uneakharsh