Padin215
Padin215

Reputation: 7484

Xcode 5 Autolayout and making UIView's width equal to height

I am using autolayout. I have a UIImageView in IB. I want to make the its width equal to its height.

I learned how to do most of this stuff in Xcode 4. I know how to do it programically, but that produces and error that Apple hasn't fixed yet:

'Auto Layout still required after executing -layoutSubviews. UITableViewCell's implementation of -layoutSubviews needs to call super.'

So how do I set the this constraint in Xcode 5 Interface Builder?

Upvotes: 4

Views: 5405

Answers (4)

Raj iOS
Raj iOS

Reputation: 1057

As Timothy Moose commented, you have the option to keep aspect ratio in Xcode 5.1.

Make sure you have width and height the same. Add the aspect ratio constraint by using control drag to itself.

enter image description here

It will automatically ensure both height and width are maintained.

Upvotes: 8

Timothy Moose
Timothy Moose

Reputation: 9915

In Interface Builder, you can control drag from a view to itself and you'll get Aspect Ratio as one of the options (Width and/or Height are also options, depending on the direction you drag).

The default value is the current aspect ratio of the view, but you can customize this to anything you want in the constraint's attribute inspector.

Upvotes: 3

John
John

Reputation: 2660

I haven't verified this but here is a question that answers this.

Auto-Layout Constraint: How to make a view maintains its width/height ratio when resized?

Upvotes: 0

Scott Berrevoets
Scott Berrevoets

Reputation: 16946

You can't set that type of constraint in Interface Builder. I also don't think the error you're getting is because of a bug on Apple's side, it generally means that you have an ambiguous layout.

Upvotes: 1

Related Questions