IOS - How to edit a view's scale by Swift?

4

I have a viewview viewV and would like to change your Width and Height shown in the image below via Swift code.

    
asked by anonymous 29.03.2016 / 14:32

2 answers

6

You can do this with this code below:

let x = CGFloat(0)
let y = CGFloat(0)
let height = CGFloat(100)
let width = CGFloat(100)

viewV.frame = CGRectMake(x, y, height, width)

Your normal viewV

YourviewVModifiedwiththecode

    
29.03.2016 / 22:29
1

It would be interesting to use% s of% s for this. It would be via code (more or less) like this:

// Constraints
let topConstraint = NSLayoutConstraint(item: viewV, attribute: .top, relatedBy: .equal, toItem: viewV.superview!, attribute: .top, multiplier: 1, constant: 0)
let leadConstraint = NSLayoutConstraint(item: viewV, attribute: .leading, relatedBy: .equal, toItem: viewV.superview!, attribute: .leading, multiplier: 1, constant: 0)
let widthConstraint = NSLayoutConstraint(item: viewV, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: 667)
let heightConstraint = NSLayoutConstraint(item: viewV, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: 267)
NSLayoutConstraint.activate([topConstraint, leadConstraint, widthConstraint, heightConstraint])
    
06.03.2017 / 20:44