jorjj
jorjj

Reputation: 1599

How can I resize the view background image?

I'm adding to background image in my view. But when I try to resize the image nothing happens. I know the image is too big, but I'm able to ScaleAspectFill:

self.view.backgroundColor = UIColor(patternImage: UIImage(named: "matchfield.jpg")!)
self.view.contentMode = .ScaleAspectFill

This code is not working. How can I do the resizing?

Upvotes: 1

Views: 1808

Answers (2)

easysaesch
easysaesch

Reputation: 169

Considering Stanly's answer, try to put autoresizingMask stuff into square brackets and use commas instead:

var image : UIImageView
image = UIImageView(frame:CGRectMake(0, 0, 200, 150))
image.autoresizingMask = [UIViewAutoresizing.FlexibleBottomMargin, UIViewAutoresizing.FlexibleHeight, UIViewAutoresizing.FlexibleRightMargin, UIViewAutoresizing.FlexibleLeftMargin, UIViewAutoresizing.FlexibleTopMargin, UIViewAutoresizing.FlexibleWidth]
image.contentMode = UIViewContentMode.ScaleAspectFit

Upvotes: 0

user3600801
user3600801

Reputation:

Use following code to resize...

var image : UIImageView
image = UIImageView(frame:CGRectMake(0, 0, 200, 150))
image.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth
image.contentMode = UIViewContentMode.ScaleAspectFit

Upvotes: 0

Related Questions