2,150 questions
0
votes
1
answer
363
views
Constraining Text Field to Button in Swift
I have a button I created in my storyboard, but have a custom UITextField that needs to be implemented in code, I am trying to place the text field so that it's 20 pixels above the button, but I am ...
0
votes
1
answer
124
views
Programmatically move contraints - Xcode reports error on not existing constraint
I have create a UIView extension which should move subviews into another (sub-)view while keeping the constraints intact. The constraints between the subviews and the the view as well as 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 ...
0
votes
1
answer
1k
views
How to make image View Height and width (Aspect Ratio) dynamic according to the image size in swift 4 or 5? [closed]
I have a collection view in which I'm populating images that I get from the backend. I'm using AutoLayout and I've statically set the imageview's height as 180 and width as screen width. But I've ...
-1
votes
1
answer
122
views
Auto-Layout, layout constraints producing puzzling results UIKit Swift 5
I am currently getting to grips with UIKit and trying to build a simple game to do so. The first part I am struggling to understanding is auto layout, the necessary constraints and their behaviour, as ...
0
votes
2
answers
662
views
How to update the constant height constraint of a UIView with IBOutlet
I'm trying to change the height of my menu view so that it opens, but when I add the IBOutlet of the NSLayoutConstraint it keeps crashing my app with the same error code. I Triple checked that the ...
1
vote
1
answer
216
views
Constraint is deactivated by the system
I have a constraint in my view controller that gets deactivated by the system for some reason when the app goes into the background and then coming back to foreground. I haven't been able to pinpoint ...
0
votes
1
answer
912
views
UIKit: how to animate a constraint change with a programmatically created constraint?
I have followed this answer to instantiate a view from a XIB file:
extension UIView {
class func fromNib(named: String? = nil) -> Self {
let name = named ?? "\(Self.self)"
...
0
votes
1
answer
447
views
How do I update constraints after changing UIButton's image
I have a mini game in my project where you have to guess a flag of a country, I don't use Interface Builder, all UI is written in code. When user taps one of the flags I load new set of countries to ...
1
vote
1
answer
450
views
Swift texfield input: pickerView, throws constraint error
When I click on of the five textfield, the picker view comes up but this error comes up. when you click on the lower two textfields the picker view doesn't´t come up. If I make this whole thing ...
2
votes
2
answers
1k
views
Sizing UIButton depending on length of titleLabel
So I have a UIButton and I'm setting the title in it to a string that is dynamic in length. I want the width of the titleLabel to be half of the screen width. I've tried using .sizeToFit() but this ...
0
votes
1
answer
40
views
Issue with clicking vertically aligned Bar Buttons outside of the Navigation Bar
I am trying to align two UIBarButtonItems vertically on the right side of my UINavigationBar. I am using a custom view, and aligning two buttons within that.
Here is the code:
let ...
0
votes
1
answer
1k
views
Change constraint when device is rotated
I'm using the following layout as a custom popup UIView in Xcode 13 (the white background is transparent):
When the screen orientation is changed to landscape mode, the constraint at the top and ...
0
votes
1
answer
703
views
Self-sizing view won't lay out correctly in UIStackView
I have a container group (the radio group) that contains a UIStackView, and that stack view contains a bunch of items that can have varied sizes, depending on their label content. They have two labels ...
0
votes
1
answer
138
views
Unable to add top and centerX constraints programmatically
let imageView = UIImageView(image: UIImage(named: "Loading"))
imageView.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
imageView.center = self.view.center
self.view.addSubview(...
0
votes
1
answer
81
views
NSLayoutConstraints not added when activated in extension function
I have convenience extension functions that allow me to add constraints to UIViews:
enum Constraint : String {
case top = "topAnchor"
case bottom = "bottomAnchor"
...
0
votes
2
answers
544
views
iOS Swift Constraints not working, subview of UITableView disappears when translatesAutoresizingMaskIntoConstraints = false
I've dealt with programmatically creating constraints, but something isn't working this time and I can't figure out what it is.
override func viewDidLoad() {
super.viewDidLoad()
let imageview ...
0
votes
1
answer
74
views
How to stack multiple UICollectionView's vertically on the same UIViewController?
What's needed to stack multiple UICollectionView's vertically on the same UIViewController? I have added my code below and the issue that I am having is I do not see the StoryCollectionView. When I ...
0
votes
1
answer
563
views
Display uiview with dynamic height based upon content using NSLayoutConstraints programmatically in Swift
I am working on view which will have a label and few buttons. The length of view should depend upon the text in label. I have tried to place label and button in the view vertically and add constraints ...
2
votes
2
answers
706
views
NSLayoutconstraints not working as expected
Below code is not working as expected. the InfoLabel is not added to the view. I am calling the below methods in the order mentioned from viewDidLoad. Any quick help/insights will be great.
Thanks!
...
2
votes
1
answer
725
views
How can I attach view to keyboard top edge using constraints on iOS
I have a simple view attached to the bottom of view controller:
let view = UIView()
view.backgroundColor = .gray
view.translatesAutoresizingMaskIntoConstraints = false
let viewBottomPositionConstraint ...
0
votes
3
answers
640
views
Constraints appear to change UIButton frame size
Background
I’m trying to create a UIButton with a 300px width and 200px height.
Then, I’m trying to position that UIButton centred horizontally and 50 pixels from the bottom.
When running the code in ...
0
votes
3
answers
631
views
Combining constraints with variable and fixed heights on UIView in Swift
Update:
Thanks everyone for the unique approaches. Appreciate your insights.
Background:
I have written some code below in Xcode Swift 5 that creates four equal sized rectangles that resize depending ...
-1
votes
1
answer
518
views
Constraints not updating and view is letterboxed when rotating device
Background:
When rotating the device, the view myView becomes letterboxed instead of resizing to fit the screen, see image below.
On the storyboard, centreX and centreY constraints are set.
In the ...
0
votes
1
answer
219
views
How to convert NSlayout constraint to integer?
I want to append 20 constant value to nslayoutconstraint, how can I do that ??
Let moduleConstraint = module.bottomAnchor.constraint(equalTo:mainScroll.safeAreaLayoutGuide.bottomAnchor)
-1
votes
1
answer
478
views
Layout constraints are not working iOS swift [duplicate]
I added leading | trailing | top | height constraints but the view is not visible.
let view = UIView()
view.backgroundColor = .orange
self.addSubview(view)
NSLayoutConstraint.activate([
...
0
votes
1
answer
380
views
Resizable/Dynamic UICollectionView width (not a cell dynamic width!!)
I have a horizontal UICollectionView with green background (attached image) and I`d like to adjust its width depending on how many cells are available. After that, the button needs to be attached to ...
0
votes
1
answer
537
views
UIKit Change Presented View Controller's Layout Constraints Relative to Parent View
I'm working on a project in UIKit, without storyboards (only programmatic layout constraints) and, following this, I have a custom view controller like this:
@objc public class testController: ...
0
votes
1
answer
189
views
Changing height of stack through code and then resetting it in iOS swift
I have a stackview whose height is 250. I want to program:
When the button is tapped, the stack should go to the top of screen.
Then after a few seconds it should go back to its height of 250, which ...
0
votes
0
answers
65
views
Swift LayoutConstraint breaks on keyboard frame change
I have a simple ViewController with a UITextView inside of a UIStackView. I've also stored an NSLayoutConstraint which is the bottom anchor of the stackView.
When the textView becomes first responder ...
0
votes
1
answer
48
views
iOS - Issue with NSLayoutConstraint when rotating device
I have an iOS view consisting of a collectionView with a headerView. The view displays fine, but when I rotate the device (iPad), the header elements get duplicated and don't fit correctly. The output ...
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 ...
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 "...
1
vote
0
answers
68
views
UIScrollView too close on home bar
Whenever I run my iOS app on a device that has a home bar, the bottom of a UIScrollView or one of its descendants will render too low.
My app has a bottom navigation. I made the scroll view ...
0
votes
1
answer
470
views
UILabel not showing all text
I have two labels in a UITableViewCell subclass. I want both labels to be multiline labels, so I have set the number of lines to zero for both of the labels. But the problem is that the labels keep ...
0
votes
1
answer
116
views
UITableViewCell not autosizing
I have two labels in a UITableViewCell subclass. I want both labels to be multiline labels, so I have set the number of lines to zero for both of them. But the problem is that my table view cell is ...
1
vote
1
answer
98
views
Autosize UITableViewCell with two columns
I have a UITableViewCell that has two columns in it. Each column is a UILabel and each label is multiline (numberOfLines = 0).
What I would like is to have the table view cell vertically sized based ...
1
vote
1
answer
94
views
NSLayoutConstraints not cooperating with UIImageView
In my UIView subclass, I have one image view and three labels:
let imageView = UIImageView()
let firstLabel = UILabel()
let secondLabel = UILabel()
let thirdLabel = UILabel()
The image and texts are ...
1
vote
0
answers
117
views
Unable to simultaneously satisfy constraints of InputAccessoryView
I have an InputAccessoryView with a single button in. However, I am getting the following output.
I have set up my InputAccessoryView in my ViewController as below;
lazy var customInputView: ...
0
votes
2
answers
57
views
More complicated AutoLayout equations
Hi Please take a look at the following mockup:
I wanted to know how I can create the constraint from above:
V2.top = C1.top + n * V1.height
Because this is not something like the default equation ...
0
votes
1
answer
288
views
NSLayout Constraint not working on Custom View
I am creating a custom UIView in swift, here is the code for the custom View,
class FormField: UIView {
@IBOutlet var viewLabel : UILabel!
@IBOutlet var textField: UITextField!
@...
2
votes
1
answer
773
views
Swift remove space of Navigation Bar from UITabBarController
I'm making an iOS application, creating the UI programmatically, so far what I'm trying to do is display a map with MapKit inside one tab of UITabBarController, and I'm trying to make the map to use ...
-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 ...
1
vote
2
answers
1k
views
Difference between using NSLayoutConstraints initializer compared to Anchors for setting constraints
Why do some developers add constraints like this:
NSLayoutConstraint(item: myView, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1.0, constant: 20.0).isActive = ...
0
votes
0
answers
391
views
Animate height constraint doesn't work as expected
I am trying to animate a view in a ViewController using Layout Constraints. My goal is to transform the view's height from 0 to finalHeight in order to make the view "appears" from the ...
1
vote
2
answers
3k
views
Swift - Animate Constraints in Custom UIView
I am trying to animate constraints in a custom UIView. The ending layout is correct, but I cannot get UIView.animate to work correctly, and I have seen that everyone is calling self.view....
-1
votes
1
answer
23
views
NSLayoutConstraints programmatically
I want to add constraints to a view programmatically.
This is what I did:
extension UIView {
func bottomToTop(other: UIView) {
self.translatesAutoresizingMaskIntoConstraints = false
other....
0
votes
1
answer
485
views
Move the button using the Constraint Swift Programmatically
@objc func buttonRoundPlayer(){
view?.addSubview(buttonRound)
buttonRound.setTitle("Jump", for: .normal)
buttonRound.addTarget(self, action: #selector(roundhandle), for:...
0
votes
1
answer
360
views
ScrollView is missing constraints
Swift 5/Xcode 12.4
My app uses a UIScrollView to zoom its child UIImageView (which is filled through code). This part works but the ScrollView keeps complaining in XIB that it's missing constraints ...
6
votes
1
answer
813
views
iOS 14: App freezes without crash report on updating constraint constant
I have a strange issue on updating a NSLayoutConstraint constant value.
I have a view controller with a custom UIView (which acts as a bottom sheet / card).
Inside my UIView class I am updating the ...