Questions tagged [layoutsubviews]

layoutSubviews is a method that is called automatically during view size changes. It can be used by a custom view to perform additional manual changes above and beyond any autoresizing behaviours

This method is called automatically and should not be called directly. UIKit will call it automatically whenever a view size changes. This could be as a result of resizing due to orientation changes. For example when the user rotates the iOS device to portrait or landscape mode.

In the custom view that implementslayoutSubviews, any view changes in addition to the autoresizing behaviours should be applied.

For further information please refer to the View Programming Guide for iOS. See the section on "Tweaking the Layout of Your Views Manually".

See also the UIView Class Reference.

149 questions
1
vote
0 answers

Autolayout in UIView where is safe to ask computed layout values?

I've got this issue. I'm using a collection view as a subview of the main view of a UIViewController. The collection view is pinned to the superview size, thus it has 4 constraints for lead,trail, top and bottom with constants equal to 0. The cell…
Andrea
  • 26,120
  • 10
  • 85
  • 131
1
vote
1 answer

Rearrange UIView Subviews if a Subview is removed in Auto Layout

I am in a need of implementing a drag and drop controller in Full-Auto Layout environment. I have achieved the dragging and dropping successfully, but the issue is if I drag a subview from another view the other related subviews behave weirdly, as…
infiniteLoop
  • 2,135
  • 1
  • 25
  • 29
1
vote
1 answer

Resizing subviews with auto layout

If I have a viewController with it's XIB, autolayout enabled and the main view (I mean self.view) have a subview in it that have the same width and height as the parent. If i put this controller inside an other controller (with the…
jerrygdm
  • 450
  • 1
  • 7
  • 22
1
vote
1 answer

Custom iOS UITableViewCells not being re-laid out when recycled

I have a UITableView which is displaying update posts from various social networks. I have custom UITableViewCell subclasses, which have a custom UIView inside, which is responsible for drawing all the labels and images, similar to how Apple…
s73v3r
  • 1,751
  • 2
  • 22
  • 48
1
vote
0 answers

UILabel resizing wrongly in LayoutSubview

I have a subclass of a UITableViewCell to show a custom cell. This class is integrated with Storyboard and therefore the frames of the properties have already been set in IB. My aim is to dynamically set a label's width according to the text it…
0
votes
1 answer

iPhone - layoutSubviews being called when updating subview

I have a custom view with a grid-like layout. When I touch each subview I want to animate them. The superview overrides layoutSubviews to create the grid of subviews. The problem is whenever I change the frame of a subview for animation, the…
jimj
  • 1,005
  • 2
  • 11
  • 22
0
votes
0 answers

viewDidLayoutSubviews being called many times on orientation change in UIViewControllerRepresentable

I'm trying to implement a zoomable image in SwiftUI to display in a page view like the iOS photos app. I'm using UIViewControllerRepresentable to wrap a controller containing a UIScrollView to achieve this, and I'm running into a strange problem…
0
votes
2 answers

What actions indirectly invalidate layout, so setNeedsLayout() call is unnecessary?

I've recently started sorting out layoutSubviews(), setNeedsLayout() and layoutIfNeeded() methods. So, setNeedsLayout() manually sets the layout as invalid, so in the next update cycle (or in the current, if layoutIfNeeded() is called) views will be…
0
votes
2 answers

UIStackView change item spacing as stack view changes sizes

Overview I have a stack view that has multiple circle views in it. The circle views could be images (like profile pictures) or anything. These views should be able to overlap if the size of the stack view is too small for the subviews. And the views…
ashipma
  • 423
  • 5
  • 15
0
votes
1 answer

Swift - UIStackView - hide if height of all items is below threshold

I have UIStackView in vertical mode filled with UIButtons. I have dynamic screen resize and if all buttons in stack view have height under some threshold, I want to hide them. How to achive this automatically? I have tried to extend UIButton and…
Martin Perry
  • 9,232
  • 8
  • 46
  • 114
0
votes
1 answer

iOS: layer (updating on CADisplayLink) added to view triggers [view layoutSubviews] 60x/sec -- Why?

I cannot figure this out. I have a view. it is a speedometer. I put a needle in the speedometer: - (id) initWithFrame: (CGRect) frame { self = [super initWithFrame: frame]; // [super initWithCoder: coder]; if (! self) return…
P i
  • 29,020
  • 36
  • 159
  • 267
0
votes
1 answer

Image on UITextField's leftView is not being rendered

I have a UITextField where I want to set an icon image on the left side. Here is my code for it. Can anyone please point out my mistake? override func layoutSubviews() { super.layoutSubviews() self.layer.cornerRadius = self.bounds.height/2 …
Natasha
  • 6,651
  • 3
  • 36
  • 58
0
votes
1 answer

How to properly manage elaborate Collection View cellForItemAt method?

I'm a fairly new developer and I have some long cellForItemAt methods. I have a feeling I'm missing something important. In this ViewController I have a segmented control that filters data with a boolean taskView property. Here's what my…
0
votes
1 answer

layoutsubviews infinite loop in a UIButton subclass

An app I'm working on has a customized UIButton class that is supposed to create a rounded button of a size depending on its title. From when I've updated to iOS 13, something strange is happening: the first time the view containing these buttons…
Aleph72
  • 877
  • 1
  • 13
  • 40
0
votes
1 answer

place NavigationBar subview behind the NavigationBarItem and title

I want to add a view below everything that's on the navigationBar. I need to add them as subviews to my NavigationBar so that they appear on any detail ViewController. Here is what I tried so far inside my custom NavigationBar subclass (I call this…
WalterBeiter
  • 2,021
  • 3
  • 23
  • 48