First, disable automatic translation of autoResizingMasks to constraints.

Next, add the constraint for the fixed width.

Finally, add the contraint for the fixed height.

Note that I am setting a fixed width of 200 and a fixed height of 300.

Important note: Since we are adding our constraints programmatically, we need to do it in our UIViewController’s method:

(as stated in https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/AdoptingaFull-ScreenLayout/AdoptingaFull-ScreenLayout.html)
Also, remember to call [super updateViewConstraints] when implementing the above method.

EDIT:
There is another way to define fixed width and height using constraints programmatically.
We can use NSLayoutAttributes to define this.

References:

https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/Articles/formatLanguage.html

https://developer.apple.com/library/mac/documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/AdoptingaFull-ScreenLayout/AdoptingaFull-ScreenLayout.html

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/updateViewConstraints

Happy Goals for iOS

Happy Goals for iOS

Want an app to help you track and achieve your goals, without the complex stuff, saving you from headaches? Checkout Happy Goals - Habits & Goals Tracker now in the App Store! Happy Goals has been featured in the App Store in over 32 countries. Start now, better late than never!

 

Thank you!

%d bloggers like this: