This post has written about
- Adding auto layout constraints to UI object by using interface builder
- Changing auto layout constraints by using swift language
Auto layout constraints can be defined to work with different Size classes. Size classes that is applied to different devices and orientations can be change with the below Pop over in the interface builder.
There is a UIImageView object on the UIViewController of this class. To center it horizontally on the screen select the UIImageView click on the align button to display Add New Alignment Constraints pop up.
UIImageView needs to be 10 point below from the top layout guide. And it need to have width and height of 200 points. To do that click on the pin button to show pop up that can be used to add constraints for above requirements.
To see changes on the storyboard. Click on the Resolve Auto Layout Issues button that shows a menu like below .Then click on Update Frames.
Change Auto layout Constraints with Swift Code
Create IBOutlet to UIImageView width and height constraints.
@IBOutlet weak var imageHeight: NSLayoutConstraint!
@IBOutlet weak var imageWidth: NSLayoutConstraint!
Write a method like below to change Auto layout constraints which is referred through outlets by using swift code.
func resizeImage(size: Int){
imageHeight.constant = CGFloat(size)
imageWidth.constant = CGFloat(size)
}
Value of instance of NSLayoutConstraint can be changed by assigning new CGFloat value to that instance's constant property.
No comments:
Post a Comment