Reputation: 179
I am trying to set the image without any uiimageview,now I have the image but it is repeated horizontally twice I want to scale and fix it to screen size how do u do that??
I have tried some methods but nothing worked out
below is my code:
- (void)viewDidLoad {
[super viewDidLoad];
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"background_themee.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// self.view.backgroundColor = [UIColor colorWithPatternImage:image];
// UIGraphicsBeginImageContext(self.view.frame.size);
// [[UIImage imageNamed:@"background_themee.png"] drawInRect:self.view.bounds];
// UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_themee"]];
// Do any additional setup after loading the view.
}
thanks in advance for your suggestions!!
Upvotes: 1
Views: 1134
Reputation: 1265
you can select scale to fill or aspect fill/fit according to your need
Upvotes: 1
Reputation: 7588
colorWithPattern
will always repeat the image over the view. If you open in iPhone, it maybe appear 2 times image. And if you run on iPad, there might show 4 image. So it is not good for background image.
What you need is a UIImageView with contraints properly set and contentMode set to AspectFill.
Upvotes: 1