Tag: nslayoutconstraint

Auto Layout Constraint With Dynamic Variable?

Is it possible to have an Auto Layout constraint (NSLayoutConstraint) with a dynamic constant/multiplier? For example, this would be a bog standard NSLayoutConstraint: NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:obj1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:obj2 attribute:NSLayoutAttributeLeft multiplier:1 constant:0]; Then here would be an alteration of that constraint but a dynamic variable in the constant: NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:obj1 […]

Centering view with visual format NSLayoutConstraints

I am trying to center a view using the visual format language. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@”H:|-[_progressView(300)]-|” options:NSLayoutFormatAlignAllCenterY metrics:0 views:views]]; (views is a NSDictionaryOfVariableBindings containing _progressView) It does not center my view (width: 300) within the self.view (width: 768). It aligns it left with an 8 pixel margin, as if I would have only written @”H:|-[_progressView(300)”. Is […]

Autolayout + constraints for dynamic table height based on total rows

First of all this ain’t about dynamic cell’s height. So don’t mix it up. I have a scenario in that I created three cards Detail card: Show specific details for location Chart card: Show different charts based on selection More details card: Card shows more details Below are screens for above cards: View hierarchy for […]

UIStoryboard how to replace constraints programmatically?

I have a view controller laid out in a storyboard with autolayout enabled and am looking for a way to change constraints to allow for my view to rotate into landscape and rearrange buttons on the screen. When I try the code below, I get about two dozen “unable to satisfy constraints, breaking constraint…” messages […]

How to resize a parent view based on the size of subviews layouted with Autolayout

I am preparing a custom view which looks similar to the example shown in the screenshot. I add all user interface components (labels, text fields, radio buttons, ..) at runtime. To position the elements I use Autolayout constraints. This part works fine so far. The number of elements varies from context to context. I wonder […]

Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one

I know how to modify a existing constraint. But I would to know if someone has found a solution to get a constraint without save this one as a property. Current solution to set Constraint height: 1) save NSLayoutConstraint in a variable: NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:myView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:20]; [self.view addConstraint:heightConstraint]; […]

UITextView inside UIScrollView with AutoLayout

I am trying to place UITextView inside UIScrollView with AutoLayout with no luck. What I have tried is, I placed UIScrollView inside the main view in Storyboard I placed UITextView inside UIScrollView in Storyboard and disabled Scrolling Enabled I set constraints (leading, trailing, top, bottom) on UIScrollView I set constraints (top, leading, trailing, height) on […]

Setting constraints to UIScrollView

Need some help to set constraints to UIScrollView. I tried to follow the instructions here: https://developer.apple.com/library/ios/technotes/tn2154/_index.html (Mixed approach). Setting 4 sided constraints to UIScrollView. Then set 4 sided constraints to the buttonContainer. This the result: However xcode is giving this error message: If I try xcode’s recommendation, either the scrollview will not scroll, or it […]

Align text fields using dynamic constraints

I’ve been learning how to make iOS apps, and have come across a minor annoyance. I can’t find an easy way to align my text inputs. Looking at the below screenshot, you will see that I’ve managed to align my text fields, which is what I want. However, I did this manually by changing the […]

Understanding Constraints using Xcode and Manually Coding

I just read few information about how to manipulates constraints number programatically, but I think I need to see it visually using Xcode. So I decided to put a UIView like this and see what’s going on with Constraints : automatically it will create 4 constraints : after modifying the number, I got what’s the […]