2,150 questions
1
vote
1
answer
22
views
Multiline text not fitting into UILabel
I have this code :
class ViewController: UIViewController {
private var nameLabel = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after ...
0
votes
1
answer
155
views
How to add constrains inside custom UIView?
I want to add constrainst to UILabel
My custom UIView class:
class LabelView: UIView {
public var label: UILabel = UILabel()
override init(frame: CGRect) {
super.init(frame: ...
0
votes
0
answers
101
views
Add Constraints Programmatically in swift
I am trying to add constraints programmatically for 3 different views but the height of the views is not adding properly.
if tags.count == 0 && images.count == 0
{
...
0
votes
1
answer
1k
views
Setting width constraint to a UIView with a function call doesn't work anymore. iOS ( Xcode 12.0.1 )
I had the following code in Swift to fill a status bar within its container, in relation to the completion of a quiz percentage by changing its width dynamically and it worked fine in 2018:
func ...
0
votes
1
answer
141
views
Swift, iOS: Water mirror text lable & image icon
I am getting the table cell in mirrored water image. Please check the screen shots:
The constraints are:
1
vote
2
answers
1k
views
Bind frame to superview bounds UIView extension
Pretty often I find myself writing these lines of code:
myView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
myView.topAnchor.constraint(equalTo: myView.superview....
-1
votes
2
answers
290
views
Resolving UILabel constraints issues
I'm a beginner in UIKit, and I'd like to achieve this layout in a UITableViewCell.
UIStackView1 is composed of arranged subviews like these:
Both Header Label and Value Label are UILabel, connected ...
3
votes
1
answer
470
views
NSLayoutConstraint - Two items, one line, spacing priority
I have two labels on one line. I need the second label to be right up against the end of the first label, but I need to make sure the second label never runs past the edge of the screen.
So I have ...
1
vote
1
answer
515
views
NSStackView, fill view when one of the subviews is hidden
I have a vertical NSStackView that has this behavior. It has two subviews, one of them at top of the stack view, that will have a fixed height.
Then, there is another view that will cover the ...
0
votes
1
answer
82
views
forEach use in nslaoyutconstraints
I want my swift code to see if there is a way to use something similar to a for Each loop when creating constraints. Right now the code would not compile. Where $0 is would be b4 in a normal setting. ...
0
votes
0
answers
39
views
Adabtive Autolayout constrain in UICollectionViewHeader
In UICollectionViewHeader this code resizes everything perfectly when the header is on the screen but if I scroll down (to footer for example) and change orientation while footer is on the screen, the ...
0
votes
1
answer
43
views
IB — Initialize specific custom UIView depending on conditions
I have the following classes:
/**
* This is basically an empty class and exists for the purpose of being able to
* define IBOutlets as BaseHeading, regardless of which specific heading is used in ...
0
votes
1
answer
2k
views
How to change the intrinsic content size through its priority
I want the second label (subview2) to stay intact and have the first label (subview1) shrink as the size of the container view decreases in size, but the second label is still shrink no matter how I ...
0
votes
1
answer
3k
views
How do you use UIEdgeInsets?
I've been trying different ways on the Playground, but the margins are not being implemented. I'm trying to understand the proper way of using UIEdgeInsets (and NSDirectionalEdgeInsets).
The ...
3
votes
1
answer
870
views
What is system spacing in a layout?
I'm having difficulty understanding what "system spacing" or "standard spacing" between views are.
import UIKit
import PlaygroundSupport
let rootView = UIView(frame: CGRect(x: 100,...
0
votes
2
answers
473
views
Swift - How to set spacing between variable number of buttons in Horizontal StackView?
I'm using a horizontal UIStackView that can contain up to 3 UIButtons. (could be just 1, could be 2, or 3)
I want to have them centered, with the same space between each of them, like so:
I don't ...
1
vote
1
answer
49
views
UIView is Being Over Written Every Time Func is Called
My swift codes goal is to place a uiview every time the button is pressed. In my gif you can see every time the blue button is called it is over written. When the code is pressed the gif should have 2 ...
-1
votes
1
answer
32
views
var constraints not appearing when assigned to a function that creates a view
I want my swift code to use var constraints to let the objects added to the code. I have added a gif below of what I am looking for. Right now the code below compiles but the black view you can see in ...
1
vote
1
answer
124
views
View Controller loses connection to constraints in IBOutlets when switching tabs in UITabView
OK, so here's the relevant bit of my code:
class MyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var questionView: QuestionView!
@IBOutlet weak ...
-1
votes
1
answer
349
views
How to set a buttons constraints equal to the safe area in Swift?
I have simple code for a UIButton:
let myButton = UIButton()
myButton.setImage(#imageLiteral(resourceName: "cross"), for: .normal)
myButton.tintColor = #colorLiteral(red: 1.0,...
0
votes
1
answer
34
views
My UIView anchors in my custom cell keep changing when I scroll in my collection view
I have a messaging app and the messages displayed are in a collection view, i have a custom cell in which i have a text view that displays the message and then I put the textview inside of a UIView so ...
-1
votes
1
answer
1k
views
How to set Safe Area Layout for new IPhone Devices in swift
I have created a simple view.Xib file, if internet connection interrupts or disconnects for any reason my view will be displayed at the bottom.
For this I have set programmatically NSLayoutConstraint.
...
0
votes
0
answers
85
views
Revert NSLayoutConstraint of UIView after changing the constraint
Currently, I am expanding a custom view inside a scrollview to
fullscreen after the user taps on it. But I want the View to come back
to the original position once the user taps on it again. Note:- I ...
0
votes
2
answers
420
views
Swift constrain view to other view that has been transformed
I have a highlightView which I would like to constraint to another view. This is my function for it:
func showHighlightView(viewToHighlight: UIView, height: CGFloat) {
self.view.addSubview(...
1
vote
1
answer
85
views
iOS14 - ViewHierarchy changes do prevent UIView extension to work
Using iOS14.0.1, Xcode12.0.1 and Swift5.3,
With iOS14, the following UIView-extension no longer works properly:
@discardableResult
func anchor(top: NSLayoutYAxisAnchor?, leading: NSLayoutXAxisAnchor?,...
-2
votes
2
answers
330
views
Unsatisfiable Constraint for NSLayoutConstraint changed programmatically - swift
I'm setting up a constraint in viewDidLoad and then changing its constant when the keyboard shows up.
This is the initial set Up
bottomConstraint = NSLayoutConstraint(item: bottomBar, attribute: ....
1
vote
1
answer
112
views
Xcode giving error when I programmatically change constraints
I have a tableview that I've initialized with 4 constraints in the viewDidLoad() method. I wanted to programmatically change the bottomAnchor later in the code so I saved it as a variable bottomAnchor ...
1
vote
0
answers
405
views
UILabel apply transform and set layout constraints
I am trying to rotate a UILabel using this code,
self.itemlistLabel.text = "Playlist"
self.itemlistLabel.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)
This rotates the label,...
0
votes
2
answers
600
views
Why is NSLayoutConstraint's identifier property not working in code?
I am trying to write some conditions where the same constraint is not added twice. For example if a view already has a bottom anchor constraint do not add it again. So I tried using the layout ...
0
votes
1
answer
403
views
Swift - Autolayout constraints UIView-Encapsulated-Layout-Width
I'm trying to do UI programatically and I'm getting weird constraint errors, but when I run the app, it it looks as expected.
What I'm trying to do:
I have a ViewController TodayVC where I have a ...
0
votes
0
answers
71
views
UIScrollView zooming to a specific area of an image
QUESTION EDITED
In the xib I have the current hierarchy:
UIView (containerScroller)
UIScrollView (imageScroller)
UIView (imageContainer)
UIImageView (image)
For some reason I check the UIScreen....
2
votes
1
answer
845
views
String Boundingrect calculation issue when string contains '\n'
I develop a Whatsapp style feature inside our app. messages are parsed from JSON and then created as text (+ optional image) messages inside a UITableView (each message is a custom cell).
The message ...
0
votes
1
answer
200
views
IOS keyboard is blocking the SubView
I have added a subview to my UItableView when No result found. but I have a problem with the portion of "No result found"UIView. it is centre and block by iOS keyboard. how can I fix the ...
0
votes
1
answer
276
views
Auto-Layout: "center horizontally" does not seem to resolve inequality ambiguity of width/x-position, within a UICollectionViewCell
Suppose I have a UIView called inner, which is a subview of a UICollectionViewCell's Content View in Interface Builder. The collection view uses flow layout and uses collectionView(_:layout:...
0
votes
1
answer
27
views
Swift4 after scrolling UITableview, animating UITableview frame is wrong
testView is subview
there are testView and view NSLayout
self.view.addSubview(testView)
testView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint(item: testView, attribute: ....
2
votes
2
answers
1k
views
UIStackView with custom constraints - "Unable to simultaneously satisfy constraints" when changing axis
I've stumbled upon an issue with UIStackView.
It has to do with the case when there are some custom constraints between the UIStackView and its arranged subviews. When changing the stack view's axis ...
-1
votes
1
answer
2k
views
addSubview and addArrangedSubview not showing content
I'm adding a UILabel to a UIView and then adding the UIView to a UIStackView, but the UILabel is not showing.
override func viewDidLoad() {
super.viewDidLoad()
configureStackView()
...
1
vote
1
answer
45
views
Why is Child Table View not sizing properly?
First off, please do not propose a "clever" solution suggesting I remove my TableViewController as a child view. Thank you.
Summary
I am adding a Tableviewcontroller programatically , as a ...
0
votes
1
answer
757
views
How to set two UILabels compression priority to make one push the other vertically?
One image is worth a thousand words:
These two labels are in a UICollectionviewCell. These are the activated constains on the labels:
blue.topAnchor.constraint(equalTo: container.topAnchor)
blue....
0
votes
1
answer
83
views
Unable to Anchor UIImageVIew in UICollectionViewCell (programmatically)
Working on specing out a view in Playground and can't seem to figure out why UIIMageView is being placed in the center of a UICollectionViewCell.
Relevant Code:
class BookCell: UICollectionViewCell {
...
-1
votes
1
answer
46
views
Constraint between UIButton and UIView
enter image description hereI'm new to Swift development and it's been few hours since i'm trying to fix this issue that I am facing. The error is with the constraints. Here's my code below:
// My ...
2
votes
2
answers
298
views
How to animate constraints one by one in IOS?
I have 6 views. I want to animate the constraints one by one, ie, i need the animation on second view only after first, then after second the third and so on. I have added the code in the completion ...
0
votes
1
answer
707
views
how to popup tableView from bottom of screen?
in my project I want that after presenting viewController, tableView popup from bottom of screen until showing all the content of tableView. the UITableViewCell height is dynamic and I'm using swift ...
-1
votes
1
answer
642
views
Swift - Remove constraints from a view inside a UICollectionViewCell
I have added programmatically some constraints in the views I have inside of a custom UICollectionViewCell, but I've noticed that when a cell is being reused, the constraints are probably being re-...
1
vote
1
answer
216
views
How to find which view is causing 'Unable to simultaneously satisfy constraints'
Sometimes I will get a layout issue, but I won't be sure which view is sending it. First I get logs like this
2020-07-17 18:46:00.243783+0200 your-app[97175:3182603] [LayoutConstraints] Unable to ...
1
vote
1
answer
135
views
TableView Disappears from the View Hierarchy Debugger
I use xCode 11.5. If I wrap an Empty UIView and a UITableView into a stack view and the choose Fill for the distribution way, the UITableView will disappear in the Simulator interface. I've checked ...
0
votes
1
answer
102
views
Adding top and bottom constraints causes UILable to be squished
Programmatically I created a custom UITableViewCell and tried centering two UILabels vertically inside it. But the UILabel ended up being squished. Doing the same thing in Interface Builder with a ...
0
votes
1
answer
1k
views
SwiftUI Software keyboard + two TextFields = Constraint conflict
TL;DR
Tapping a second TextField while the keyboard is showing triggers a constraint conflict.
Details
The code below is runnable as-is. Tap the top TextField, then the one below. The Xcode console ...
1
vote
2
answers
695
views
Swift: UIButton not clickable, NSLayoutConstraint heightAnchor issues
I am Building a simple hangman game.
I have built a simple keyboard out of UIButtons. The keyboard is inside a subview and each row is a seperate subview.
The Buttons are not clickable, I can get the ...
-1
votes
1
answer
90
views
Two UILabels side by side in UITableviewCell programmaticaly with priories in swift
I would like to put programmaticaly 2 labels side by side in forcing the full size for the second label:
With my current code, depending of datas, sometimes, it works, sometimes the status label is ...