Reputation: 1599
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
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
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