2,150 questions
1
vote
0
answers
55
views
Multi-line title in UIButton in a UITableViewHeaderFooterView causes UIViewAlertForUnsatisfiableConstraints warnings
I need to show occasional long texts in a UIButton in the section header of my UITableView. The following simple example code shows the issue:
import UIKit
import SnapKit
class ViewController: ...
2
votes
1
answer
9k
views
How to add a subview with constraints to make the subview with the same frame as its superview?
Within UIView I have a method presentView():
public func presentView() {
UIApplication.sharedApplication().delegate?.window??.addSubview(self)
let blurEffect = UIBlurEffect(style: ....
183
votes
19
answers
107k
views
Can I change multiplier property for NSLayoutConstraint?
I created two views in one superview, and then added constraints between views:
_indicatorConstrainWidth = [NSLayoutConstraint constraintWithItem:self.view1 attribute:NSLayoutAttributeWidth relatedBy:...
8
votes
1
answer
5k
views
How can I activate, previously deactivated constraint?
I keep references to my NSLayoutConstraint
var flag = true
@IBOutlet weak var myConstraint: NSLayoutConstraint!
Then for some @IBAction I activate/deactivate depending on my flag variable:
@IBAction ...
2
votes
1
answer
114
views
Is it possible to access/manipulate the constraints in a nib file from the view it's loaded into?
Example project: http://cl.ly/1g1L3E2Z0r1c
I create a nib file and then create some views in it, which I then load into another view controller. In the view that I bring in, it's a subclass of UIView ...
0
votes
4
answers
702
views
iOS constraints: 4 Buttons
I would like to place 4 buttons on the screen. They should be all of the same height and width. The margin between the buttons should be 35px and the outter margin to the views border should be 20px.
...
0
votes
0
answers
56
views
NSTextView Breaks Layout Constraints on Holding Down Key (Press and Hold)
I have a simple NSTextView inside a scroll view, as follows:
self.suggestionTextView = NSTextView()
self.suggestionTextView.isEditable = true
self....
573
votes
19
answers
706k
views
How to add constraints programmatically using Swift
I'm trying to figure this out since last week without going any step further. Ok, so I need to apply some constraints programmatically in Swift to a UIView using this code:
var new_view:UIView! = ...
1
vote
1
answer
113
views
iOS Autolayout - unable to have height be lessThanOrEqualTo
I am using SnapKit for auto layout in my iOS app.
I need to show an image view at the very top of the screen. It will have an image of dynamic height and width. I need its top edge to be aligned with ...
1
vote
0
answers
145
views
UIViewControllerRepresentable loses its alignment when integrated with other SwiftUI dynamic views
Targets:
Tested with
iPhone 16 Pro with iOS 18.0 (Simulator)
iPhone 6s with iOS 15.8.1 (Physical device)
I have an UIKit UIViewController component (instance of UIPageViewController, repo: here).
I'...
68
votes
13
answers
14k
views
What is _UITemporaryLayoutWidth and why does it break my constraints?
I have a storyboard with Autolayout and Size Classes. Pretty complicated layout, and unfortunately I can't really pin down how to reproduce the problem in a new project.
But the view in question is ...
77
votes
3
answers
57k
views
When should translatesAutoresizingMaskIntoConstraints be set to true?
I've read the documentation. But I'm still not sure when I need to set it to true. In the code below if I set it to false I won't see the header at all. If I leave it as true, then everything is fine.
...
6
votes
1
answer
2k
views
SwiftUI - ScrollViewReader scroll to top including padding (anchor plus constant)
I have a ScrollViewReader and the scrollTo method works.
proxy.scrollTo(target, anchor: .top)
The item which is scrolled to is completely aligned with the .top-Anchor.
Now I want to include the ...
21
votes
3
answers
61k
views
Programmatically creating constraints bound to view controller margins
I'm trying to make a view that will act as a sort of "panel", attached to the right side of the view controller.
That is, it is bound to the trailing, top, and bottom margins of the parent view ...
0
votes
2
answers
605
views
Constraints Not Updating When Keyboard Appears
I am making a sign up screen and would like to update a few top anchors so that when the keyboard appears, the top anchor constant decreases and the keyboard doesn't cover any text fields.
I have ...
1
vote
0
answers
68
views
NSView equivalent to UIView's systemLayoutSizeFitting
How can I calculate the optimal size of a NSView based on its current constraints and a target size?
UIView provides:
func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize
func ...
-1
votes
1
answer
126
views
How to get Spring Animations with Constraints to behave properly?
Trying to get a spring animation to work properly. I made a git repo. Basically the red view is constrained as follows:
let ac = brokenView.widthAnchor.constraint(equalTo: brokenView.heightAnchor, ...
0
votes
1
answer
631
views
How to simultaneously satisfy constraints in Swift
I am developing a Log-In screen using XCode 15.2 and the latest version of SwiftUI that is shipped in Xcode.
The Simulator I use is the iPhone 15 Pro.
The Log-In Screen has two TextFields one contains ...
-2
votes
2
answers
117
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 ...
0
votes
1
answer
83
views
I was trying to update the height constraint of my view during an animation. Its not getting updated why..?
Here is how i have configured the profile view,
-(void)addProfileView
{
if(!_profileView)
{
_profileView = [ProfileView new];
_profileView.clipsToBounds = YES;
...
0
votes
1
answer
50
views
Swift drawRect on UICollectionView subview with layout constraints draws in unexpected location
I am trying to draw onto a subview (subclass of UIView) that I have added to a UICollectionViewCell's contentView. I did this by implementing a drawRect function to draw a very simple cross in the ...
4
votes
2
answers
5k
views
changing constraints at runtime in swift
I'm really very weak in constraints part of ios. I have gone through many reference link as shown below but still not able solve my issue.
Hide autolayout UIView : How to get existing ...
3
votes
3
answers
493
views
How to move all subviews to a new parentView while keeping all constraints intact?
I would like to programmatically move all subviews of a UIView to another UIView while keeping all constraints between the subviews to each other and to the (new) parent intact.
What is the "...
95
votes
4
answers
51k
views
"Width equals height" constraint in Interface Builder
I can't find a way to create a 'square' constraint, meaning 'width equals height' in Interface Builder. I guess it's possible to add such constraint programmatically. Is there something I can do in IB?...
0
votes
1
answer
355
views
Adding Constraints to view, whose topAnchor's is bottomAnchor of UIView with dynamic height
I've created a UIView, which has buttons in it. I set the constraints like this :
NSLayoutConstraint.activate([
sampleView.topAnchor.constraint(equalTo: topView.bottomAnchor, constant: 20),
...
1
vote
4
answers
219
views
Uiimageview autolayout issue
I have this images views:
I want that for every device that the distance between the first imageview and the left side it's the same , then the distance between the first imageview and the second ...
128
votes
18
answers
173k
views
How to adjust height of UICollectionView to be the height of the content size of the UICollectionView?
I would like the UICollectionView (The red one) to shrink to the height of the content size in this case UICollectionViewCells(the yellow ones) because there is a lot of empty space. What I tried is ...
1
vote
1
answer
63
views
setup all of the properties of the stack view
I'm using an SF symbol image into a UIImageView. I have given the constrains as well. What I have seen running the same code into different simulators actually increases the width of the image but I ...
132
votes
6
answers
26k
views
What happens with constraints when a view is removed
The question I have is simple but I couldn't find any information in the documentation.
What happens with layout constraints when a view is removed from the view hierarchy (or moved to another view)?
...
0
votes
1
answer
74
views
Animation is not showing as expected in swift
I have taken image and I want flyView to be drop from top middle to 200 from top and vanishes. for that tried like this
code: here I have given constraints for flyView as flyView.centerXAnchor and ...
3
votes
1
answer
1k
views
Adding constraints programmatically makes crash
I would like to add programmatically few constraints while I slide from a bottom new table view, but so far I can not understand what am I doing wrong. In my super view I have map view which have to ...
5
votes
1
answer
949
views
Custom UITableViewCell vertical layout constraints causing error
When I run my app on an iPhone I get the following errors. When I run it in the simulator I do not. If I take the -12-| away then the cell's height collapses to something like 30 pixels and the UI ...
0
votes
1
answer
406
views
How do we constrain the layout of two Views to have the same position and size in SwiftUI?
I am a mildly experienced UIKit/AppKit developer, but I am just getting started using SwiftUI. In UIKit it is straight forward to constrain two UIView's to have the same size and position using ...
0
votes
1
answer
46
views
UITableViewCell Label's content missing
I am setting a tableView but when running the app, the label's content is not stable, sometimes it shows full content, sometimes it doesn't. Looking for advise.
I attached the images for .xib setup ...
108
votes
7
answers
132k
views
How can I set aspect ratio constraints programmatically in iOS? [duplicate]
I have used auto layout for my view controllers. I have set the V and H positions in constraints, but I want to know how can I increase my button size when it changes to 5s, 6 and 6 Plus. This is the ...
0
votes
2
answers
1k
views
iOS: UICollectionView animate height change
I have a simple UICollectionView in a view controller. I am animating the top constraint of the collection view via a button. On the FIRST button tap, the collection view cells are animating quite ...
22
votes
8
answers
24k
views
iOS - Find top constraint for a view?
I am trying to find the top constraint of the view in code.
The top constraint is added in storyboard, and I don't want to use an IBOutlet.
Logging the value of the firstAttribute in the following ...
0
votes
1
answer
148
views
Using modal view frame size in subview layout constraints
Problem: I am having some issues using the correct frame values to simulate viewport percentages when sizing subviews of a modal view-controller. I would rather size subviews using layout constraints ...
2
votes
1
answer
745
views
Getting correct frame after setting constraint
I have a method that creates a mask layer based on the current frame of my UIImageView, which works as I expected. However, in one case, I modify the height constraint of a UIImageView in the ...
0
votes
1
answer
541
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 ...
0
votes
0
answers
73
views
How does Auto-Layout resolve constraints internally?
IMPORTANT: I know how to use Auto-Layout. How to use it has been asked before already and this is not a duplicate of that question.
Auto-Layout is Apple’s cross-platform constraint-based layout system....
0
votes
1
answer
89
views
Default height of UIView with constraints (auto layout)
When you build an UI programatically with swift and constraints, you can notice that most views have some height or width, and you don't need to define it. For example UILabel, if you make constraints ...
24
votes
9
answers
22k
views
Using autolayout in a tableHeaderView
I have a UIView subclass that contains a multi-line UILabel. This view uses autolayout.
I would like to set this view as the tableHeaderView of a UITableView (not a section header). The height of this ...
4
votes
2
answers
2k
views
Is there no way to constrain the baseline of a label to match the bottom edge of another view?
I have a custom meter view. And a label that shows the numeric value graphed by the meter. Using AutoLayout constraints, I want to align the baseline of the label with the bottom of the view.
When I ...
1
vote
0
answers
232
views
UITextView in UIScrollView not scrolls to bottom
I made textview and imageview and label inside scrollview, and I add textView.isScrollEnabled = false to scroll both.
My Question is, When I click enter in the textview at the last line, My textview ...
4
votes
1
answer
773
views
Getting Warning for UI Layout in iOS "Unable to simultaneously satisfy constraints"
I have created UITableviewCell programmatically and trying to load in table view
Cell has just one imageView and UIlabel.
Although the UI looks fine , but I am seeing this warning :
Unable to ...
-1
votes
1
answer
230
views
Can't activate NSLayoutConstraint
I'm trying to set up UI for ViewController through NSLayoutConstraint. Here's the code I'm using:
class ProfileViewController: UIViewController {
private var profileUser = katyPerry
...
2
votes
1
answer
948
views
UIView not updating constraints in landscape mode
I have a UIViewController which has a UIView that plays a video.
The constraints given to this UIView are as follows.
Trailing space to : Superview
Leading space to :Superview
Top space to ...
-1
votes
1
answer
74
views
NSLayoutConstraint with VFL is working only horizontally when using '|'
I have the following implementation of a UIView..
struct LoginView {
let loginView: UIView = UIView()
func layoutLoginView() -> UIView {
loginView....
-1
votes
3
answers
1k
views
Constraint doesn't get deactivated
I am practicing auto-layout programmatically. I want to put a UIView centered in the controller whose width will be 4/5 in portrait mode but when it will go to the landscape mode, I need the height to ...