Reputation: 137
I am trying to set an image's width to 75% of the screen width and positioned in the middle.
size.width
to my image
class ViewController: UIViewController {
@IBOutlet weak var logo: UIImageView!
var sSize: CGRect = UIScreen.mainScreen().bounds
let sWidth = sSize.width
var image = UIImage(named: "logo");
image = sWidth * 0.75
@IBAction func btnPlay(sender: AnyObject) {
logo.hidden = true
}
}
Upvotes: 1
Views: 1057
Reputation: 1007
This following line shouldn't compile:
image = sWidth * 0.75
Since image is a UIImage and not a CGFloat! (sWidth is CGFloat)
Change your code as follow:
class ViewController: UIViewController {
@IBOutlet weak var logo: UIImageView!
}
And in the storyboard use autolayout:
add a these constraints between the imageView and the viewController's view:
- equal height
- equal width with multiplier of 0.75
Also -> try using the storyboard more: add the image to the imageView through the storyboard.
if you don't want to do this, add it in code inside viewDidLoad.
Upvotes: 1