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
2
votes
1 answer

Add subviews programmatically to ScrollView using Visual Format Language

scroll view - layout programmatically - swift 3 Dear friends: I hope someone could revise this project and help me before my brain been burned. Thanks in advance. The task: Horizontal Scroll - Layout an array of 4 images, square of 240 x 240 and 20…
2
votes
1 answer

How does the view redraw itself when I disable/enable a button?

If I enable/disable a button…what method would get called on the view? I’ve already placed a breakpoint on the layoutSubviews and don’t see it reaching there. Nor it reaches us to the viewController's viewWillLayoutSubviews. So I'm just curious to…
mfaani
  • 33,269
  • 19
  • 164
  • 293
2
votes
1 answer

iOS: Adding new constraints in a custom view the rely on the view's frame

I'm trying to understand when to override layoutSubviews versus updateConstraints. I have created a custom view, and that view contains other views. I can't set the constraints for the view's subviews in the custom initializer I have as I don't know…
2
votes
0 answers

LayoutSubviews is called after applicationDidEnterBackground

After some research I found that the problem occurs on all 64 bit iPads, but not iPhones. Tested on iOS 9, 10 and 11 The strange thing is that problem does not occur on WWDC 2013 Street Scroller app. Is this a normal behaviour or should I fill bug…
Alex Black
  • 138
  • 3
  • 10
2
votes
1 answer

where to put manual layout code for a UIView where parent views use autolayout?

Where to put manual layout code (or where to trigger it) for a specific child UIView I have, when the parent views themselves utilise autolayout? Notes: layout code for the view needs to use its frame dimensions after any parent view layout,…
Greg
  • 34,042
  • 79
  • 253
  • 454
2
votes
0 answers

Why does setNeedsLayout() + layoutIfNeeded() not always trigger a layout pass?

A simple experiment: I have a UITableView with the following data source method: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let identifier = "MyCellID" let cell =…
Mischa
  • 15,816
  • 8
  • 59
  • 117
2
votes
0 answers

iOS 9 autolayout and layoutsubviews different from iOS 8<

iOS 9 doesn't load autolayout in layoutSubviews() as it should.. I'm tying to add shadow under a view(container) in my custom uitableviewcell, which it works good on iOS 8, but not iOS 9. But it is working when I scroll the tableview and start…
Marc
  • 11,341
  • 3
  • 27
  • 30
2
votes
1 answer

iOS custom UIView design: init vs layoutSubviews

I have a number of custom UIViews. I constantly find myself initializing properties in the init of my custom view, but I also set the frame there too. I usually leave my layoutSubviews empty. If I don't expect my view bounds to change, is it ok to…
samonderous
  • 649
  • 1
  • 10
  • 22
2
votes
1 answer

Custom UIView layoutSubviews with orientation and animations?

I'm in a dilemma which method to use for setting frames of custom UIViews with many subviews in it and still have animations and automatically adjust to rotations. What I usually do when I create a new viewcontroller is alloc my custom view in…
Bob de Graaf
  • 2,630
  • 1
  • 25
  • 43
2
votes
2 answers

Custom UIView causes a EXC_BAD_ACCESS code = 1 in layoutSubviews

I have created a custom UIView which is instantiated 3 times from UIViewController. From the viewDidLoad method of that UIViewController: self.remainingDays = [[RemainingTileView alloc] initWithFrame:CGRectMake(20, 49, 80, 75)]; self.remainingHours…
invalidArgument
  • 2,289
  • 4
  • 24
  • 35
2
votes
1 answer

layoutSubview resetting properties of UILabel

I have a ViewController with a UIScrollView on it. On this VC I programatically adjust the frame of a UILabel which is inside the scroll view. This is done on viewDidLoad. This UILabel comes from the VC's xib file, it is not created programatically,…
Rafael
  • 368
  • 1
  • 4
  • 22
2
votes
1 answer

UITableView “swipe to delete” button frame issue

I am using a custom UITableViewCell in my app, and I am trying to adjust the frame of the “swipe to delete” button. This is what I’m doing: - (void)layoutSubviews { [super layoutSubviews]; if (UI_USER_INTERFACE_IDIOM() ==…
SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191
2
votes
1 answer

Wrong non-zero sizes on glGetRenderbufferParameterivOES

This is similar to another question that was on stackoverflow but the sizes there were 0,0 and here I am getting wrong strange non zero sizes. So it appears that this might qualify as a different problem. The problem happens when I am configuring…
nishant
  • 736
  • 1
  • 12
  • 22
2
votes
1 answer

iOS6 layoutIfNeeded doesn't trigger layoutSubViews for UITableViewCell

In my app I have a table view with customised table view cells. In iOS5 i use the following snippet of code to get the correct height for my customised cells. In iOS6 after doing a [tableView reloadData] the [cell layoutIfNeeded] will not trigger…
2
votes
1 answer

Possible to implement UIScrollView with zoomable, and aspect fit content?

I want to create a scrollView that works exactly like you pan/zoom an image in the Photo app: -A landscape image is aspect fit on the portrait screen, -You can zoom into the image, -If you rotate the device zoomed (landscape), the image remains in…
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172