Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
2 answers
74 views

How do you, or can you, create and/or "adjust" an NSLayoutAnchor property?

Say you have some large complex custom view, lazy var pinkThing: .. lazy var greenThing: .. And you want to ///For upstream views to use as they wish var pinkCenterY: NSLayoutYAxisAnchor { return ...
Fattie's user avatar
  • 12.5k
0 votes
1 answer
374 views

Unable to activate constraint with anchors.... because they have no common ancestor

I am attempting to create a Swift-based UI programmatically that resembles the layout shown below Below is my view hierarchy which I created using xib. Now I'm attempting to achieve the same through ...
Bhanuteja's user avatar
  • 801
0 votes
0 answers
51 views

LazyVGrid NSLayoutConstraint conflict

I have a LazyVGrid with minimum width and height for the cells, and the cells have a 10p padding constraint. I get this type of error : ( "<NSAutoresizingMaskLayoutConstraint:0x282eb3020 h=...
Xys's user avatar
  • 10.6k
0 votes
1 answer
73 views

Why these NSView subclass instances do not get initialised [Objective-C]?

I am trying to understand how NSLayoutAnchor works in Objective-C by converting a simple Swift app to it. The Swift app creates an NSView subclass which sets its layer's background color to a randomly ...
NotationMaster's user avatar
0 votes
0 answers
115 views

Terminating app due to uncaught exception 'NSInvalidArgumentException' Unknown layout attribute'

I am trying to give vertical space constraint programatically for Admob native ads compenents by using NSLayoutConstraint. I assigned nativeAdView in the ListTileNativeAdFactory class. (I used this ...
gurkan stack's user avatar
0 votes
1 answer
593 views

Programmatic NSScrollView with layout anchors - how to fix the scrolling?

Quite a few SO posts on implementing a scroll view programmatically but I haven't found a solution for this case... here I am adding subviews to the document view (with everything laid out using ...
chemFour's user avatar
  • 189
0 votes
2 answers
857 views

IOS SafeAreaLayoutGuide anchor for landscape screen

I've been following Paul Hudsons' Hacking with Swift tutorials and I'm up to project 6 where he uses layout constraint programmatically. I've been doing this kind of task solely using Interface ...
caffeine_inquisitor's user avatar
0 votes
1 answer
1k views

Cannot convert value of type 'NSLayoutAnchor<NSLayoutXAxisAnchor>' to expected argument type 'NSLayoutAnchor<AnyObject>

I'm trying to write an extension for UIView to make it easier to set anchors for a view. The idea was to write a setAnchors method like this: import UIKit extension UIView { func setAnchors(top: ...
tiw's user avatar
  • 565
3 votes
1 answer
452 views

Add multiplier to NSLayoutAnchor constraints in Swift

Anchor constraints simplify adding constraints but the multiplier property available in storyboard does not seem to be available for all types of constraints. For example, as per the answer here, you ...
user6631314's user avatar
  • 1,910
1 vote
1 answer
1k views

Subview that clips to parent view in Swift

I'm trying to add a subview that would always have the same size as its parent, so that it would always resize if the parent size changes. I was thinking about adding (top, bottom, leading, trailing) ...
Xys's user avatar
  • 10.6k
0 votes
1 answer
1k views

Is best to call .layoutIfNeeded() before or after constraints are changed

I have a button that changes sizes depending on certain situations. I don't need an animation done because the user never sees the change occur. Sometimes when switching back from a smaller size to a ...
Lance Samaria's user avatar
1 vote
2 answers
3k views

How to animate UIView using constraint from bottom to top?

I am creating UIView programmatically and after that i will animate that view from bottom to top using constraints. But animations doesnot show on this view object. overlay!.addSubview(...
Rahul Chopra's user avatar
3 votes
1 answer
7k views

How to update anchor constraint in swift

I would like to create a menu like android in iOS. I'm using layout constraints to setup constraints. I'm facing the issue when I'm trying to update the left constraint of an image on button click (It ...
Damodar's user avatar
  • 707
2 votes
0 answers
280 views

NSLayoutConstraint negative multiplier gives unexpected results

We are using Xcenter and Ycenter NSLayoutConstraint to position subview inside parent superview. As we need to keep the position proportional we can't use the constant value of the constraints to ...
Roi Mulia's user avatar
  • 5,886
2 votes
3 answers
7k views

heightAnchor.constraint not change height of view

I use this code: func show(){ view.translatesAutoresizingMaskIntoConstraints = false view.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true view.topAnchor....
Mohammad's user avatar
0 votes
1 answer
77 views

Structure of the cell is destroyed after UIView.transition

In one of my controllers I'm using UICollectionView with two-sided cells (there is a button on the face side of the cell, and if user is tapping it cell should show him/her the other side of the cell)....
lithium's user avatar
  • 1,302
0 votes
3 answers
126 views

ios using constraints to hide a view

Why is it that if I have a simple viewcontroller with a button, a "control view" and a tableview below it, I can't get the logic to work that will expand the tableview to cover the "view" when the ...
justdan0227's user avatar
  • 1,364
2 votes
3 answers
2k views

Is using NSLayoutAnchor bad?

I usually use NSLayoutAnchor but many times I have been advised to not use it. Is there any problem with it such as performance drop besides more complex/longer code? I've been told to use: let ...
Sin Sopheak's user avatar
0 votes
1 answer
138 views

Type of NSLayoutAnchor

No matter what I try I can't get the variations of this to work... What am I not getting? func anchorType(for string:String) -> NSLayoutAnchor<AnyObject> { switch string { case "x": ...
Magoo's user avatar
  • 2,620
3 votes
0 answers
186 views

Generics to consolidate NSLayoutAnchor

I want to consolidate the NSLayoutDimension NSLayoutXAxisAnchor and NSLayoutYAxisAnchor to create a wrapper for my anchors to avoid a long list of convenience methods The ideal syntax I was looking ...
Magoo's user avatar
  • 2,620
-2 votes
1 answer
2k views

How to convert heightAncor to CGFloat Type?

After changing the height of a UITextField using an animation, the Gradient Layer's height that is a subview doesn't match the parent height anynore. I want to convert heightAncor of a view which is ...
ISS's user avatar
  • 416
1 vote
1 answer
2k views

Removing the blank spaces on left and right side of the UISearchBar

I am creating a UI component that should display a UILabel and a UISearchBar below. However, I am not able to align them, the UISearchBar always has extra space on both left and right side (...
Peter G.'s user avatar
  • 8,024
0 votes
1 answer
842 views

Setting subviews layout anchors to UIScrollView

When i want to set top anchors of my subviews in a UIScrollView, i have to give them a constant height, otherwise scrollView won't scroll. But As they grow in number, it feels like a mess. For ...
Ahmet Gokdayi's user avatar
1 vote
0 answers
478 views

Cocoa Autolayout issue - NSTextView inside a custom NSView

I'm currently writing a Cocoa app, in Swift to exercise the language. I'm not too familiar with the AppKit framework yet, but now I bumped into an interesting problem. It simply contains an NSWindow,...
Magnificat's user avatar
0 votes
2 answers
369 views

Update widthAnchor on Device orientation

I have this constraint in my controller for a view like this: someView.widthAnchor.constraint(equalToConstant: view.bounds.width).isActive = true Now I've added this constraint in willLayoutSubviews ...
adams.s's user avatar
  • 195
5 votes
1 answer
6k views

Is layoutMarginsGuide seems to be kind of excessive?

When i was trying to create layout constraints, i read about NSLayoutAnchor class. They said: Note UIView does not provide anchor properties for the layout margin attributes. Instead, the ...
Ninja's user avatar
  • 358
4 votes
0 answers
9k views

Unable to activate constraint with anchors because they have no common ancestor

I have added a view called myView in interface builder as can be seen in the code below and have added this to the main view as a subview, I have then added three buttons programatically. I have added ...
Marcus Levi's user avatar
1 vote
0 answers
159 views

UITabBar change view hierarchy after rotating process. (or changes its position in view hierarchy)

I have a view with several subviews (with only one peculiarity I added tabBar as a subview to a view of VC) super.viewDidLoad() view.addSubview((tabBarController?.tabBar)!) view.addSubview(...
Ninja's user avatar
  • 358
0 votes
1 answer
1k views

Weird layout with tabBar.topAnchor

I have several subviews view.addSubview(collectionView) view.addSubview(pageControl) view.addSubview((tabBarController?.tabBar)!) view.addSubview(skipButton) view.addSubview(...
Ninja's user avatar
  • 358
0 votes
1 answer
616 views

How can I 'add' two NSLayoutDimensions?

Adding two NSLayoutDimension objects doesn't really make sense, but I'm trying to set the height of a container view to the height of two subviews with dynamic heights. Here's a visual representation ...
elfanek's user avatar
  • 142
0 votes
2 answers
347 views

How do I update a constraint from the Storyboard without an IBOutlet or Identifier?

I have a lot of views that are created in the storyboard, but I want them to be able to update their constraints dynamically without having to use an IBOutlet each time. I started by making a custom ...
caziz's user avatar
  • 23
1 vote
1 answer
61 views

NSLayoutConstraint:Adding line between the views

I am facing the NSLayoutConstraint issue. I created a view programmatically and wanted to add the line between two view.Line is created but it is added inside the view as shown in figure: How can i ...
jenny sam's user avatar
  • 191
2 votes
1 answer
216 views

Console warning when using NSLayoutAnchor.constraintEqualToSystemSpacingAfter

I am using NSLayoutAnchor's constraintEqualToSystemSpacingAfter for building my layout. NSLayoutConstraint.activate([ customView.leadingAnchor.constraintEqualToSystemSpacingAfter(...
ㅤㅤㅤ's user avatar
  • 57.9k
1 vote
2 answers
582 views

Translating constraints in a visual format to NSLayoutAnchor APIs

I have the following extension that I got from this SO question a few months ago, and I'd like to translate this to NSLayoutAnchor (or the more verbose layout APIs) due to the simple reason that the ...
Andy Ibanez's user avatar
  • 12.2k
3 votes
2 answers
12k views

How can I get the height of a view if I set its anchors

I am currently trying to access the height of a view which I previously set anchors for. So for example, I set the left, right, top, and bottom anchors of searchTable using the following in my ...
kbunarjo's user avatar
  • 1,375
0 votes
1 answer
2k views

Using NSLayoutAnchor to create constraints between two labels?

I'm creating a view programmatically and need to set constraints between two labels. I recently just discovered NSLayoutAnchor and feel it would be a good choice to use it but I'm unsure how to create ...
SwiftyJD's user avatar
  • 5,421
1 vote
2 answers
4k views

How can a `NSLayoutYAxisAnchor` be used as variable?

How can a variable of type NSLayoutYAxisAnchor be defined? The following doesnt work, but hopefully illustrates what I mean: let anAnchor: NSLayoutYAxisAnchor = .topAnchor NSLayoutConstraints....
Manuel's user avatar
  • 15k
2 votes
3 answers
6k views

iOS - anchor view to the top of the screen, behind status bar

I've a CollectionViewController with the default status bar and all it's embedded in a NavigationController. I'm trying to reproduce an effect in which I have a View anchored to the top of the screen,...
Ivan Cantarino's user avatar
2 votes
2 answers
786 views

Compile error in extension NSLayoutAnchor

I am trying to create an extension method on NSLayoutAnchor to accept a multiplier. I get a weird Swift compile error (Swift 3, XCode 8.2.1) not in the extension file but in the corresponding .h file ...
andrewz's user avatar
  • 5,210
3 votes
2 answers
12k views

"Cannot convert value of type 'NSLayoutDimension' to expected argument type NSLayoutAnchor<NSLayoutXAxisAnchor>

I am trying to add a subview in my Swift 3 tableView. I want the leading anchor to be related to 0.05 x the width of my parent view( tableView). When I write the following: modalView.leadingAnchor....
Thalatta's user avatar
  • 4,580
1 vote
1 answer
855 views

changing layout anchors of view on an action

I have one upperLabel, one view and button. In ViewDidLoad() method I have given some layout constraints to a view. On tap of the button I need to update those constraints(i.e the view should move ...
Karthik D's user avatar
1 vote
1 answer
4k views

How to set the NSLayoutAnchor to generate an centered subview with aspect ratio 1:1

It doesn't sound too difficult, but after hours of trying I couldn't get a proper solution. Problem: I want to set constraints (with class NSLayoutAnchor) to get a subview (colorImageView) beeing ...
LukeSideWalker's user avatar
1 vote
2 answers
4k views

programmatic constraints - cover entire superview using layout anchors

Is it possible using layout anchors to cover an entire superview's screen? Using NSLayoutConstraints, I can achieve this effect using the code below dimmingView = UIView() dimmingView....
meowmeowmeow's user avatar
42 votes
3 answers
14k views

On iOS, what are the differences between margins, edge insets, content insets, alignment rects, layout margins, anchors...?

There seem to be several different options/terms and people in the iOS community use with respect to layout (e.g. UIEdgeInsets is a type, but sometimes I hear/read "set the insets" or layout margins ...
kraeon's user avatar
  • 421
0 votes
1 answer
912 views

pin UiTableView to (view controller)view with layout anchor

I want to 'pin' a tableview to it's container, the view of a view controller. Since UIView does not have anchor properties, I try to do it with the layoutMarginsGuide. UIView does not provide ...
brainray's user avatar
  • 12.9k