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

layoutSubviews in infinite loop on iOS 8 GM

My app subclasses a UITableViewCell and implements layoutSubviews to modify the cell's contentView's width, like so: - (void)layoutSubviews { [super layoutSubviews]; // position subviews... CGRect frame = [[self contentView] frame]; …
Steveo
  • 2,238
  • 1
  • 21
  • 34
4
votes
2 answers

iOS8 Beta 3 UITableViewCell layoutSubviews infinite loop

There were auto-resizable table view cells introduced in iOS8 (WWDC Session 226 What's new in table and collection views). In my project I'm trying to implement old fixed rows height behavior. Also, the most important thing for me is to inset…
chebur
  • 614
  • 8
  • 16
4
votes
3 answers

Auto Layout causes infinite layoutSubviews loop

I'm really puzzled by this, when I use auto layout on a subview the layoutSubview method loops infinitely. All I'm doing is: - (id)init { self = [super init]; if(self) { self.backgroundColor = [UIColor grayColor]; …
Alvin
  • 248
  • 2
  • 11
4
votes
0 answers

iOS: Need to add an Add button to a search bar

I need a search control that allows a user to search for something, then if they don't find it they push an add button to add it. I need the add button to display while the user is typing the text to search for, I'm thinking to the right of the…
4
votes
1 answer

Can I make my tableview move more fluidly by reducing calling [CALayer LayoutSubviews], and how?

According to time profile, I found that my app waste too much time on [CALayer layoutSublayers] due to calling [UITable layoutSubviews]. So the action generating tableview is not smooth, whenever tap the button at first time, I would wait almost 2…
4
votes
1 answer

Calling setNeedsDisplay in layoutSubviews?

Consider a view with a custom background that is drawn in drawRect:. If the view changes size, the background need to be redrawn. Is this a bad idea? - (void) layoutSubviews { [super layoutSubviews]; [self setNeedsDisplay]; } If it is, what…
hpique
  • 119,096
  • 131
  • 338
  • 476
3
votes
2 answers

Possible to make superView intercept layoutSubviews: from subviews?

To allow for flexible layouts, I wanted to create a subclass UIView that overrides layoutSubviews: to layout all of its subviews under each other automagically and would continue to do this every time one of its subviews got resized. However, the…
SpacyRicochet
  • 2,269
  • 2
  • 24
  • 39
3
votes
1 answer

Xcode button text is accessed but the background change UI is not reflected

I created a special button as below. I can access the text value when clicked, but when I change the background value, there is no change in the UI. Does anyone know why? class MyButton: UIButton { override func layoutSubviews() { …
Ümit Bülbül
  • 512
  • 2
  • 15
3
votes
2 answers

How to execute code in LayoutSubviews only when first initialising a custom UIView

We have a custom UIView that uses constraints in Interface Builder and we have modified this view to have a custom shape which we need to draw. The shape size depends on the constraints which are applied to this custom view in Interface Builder, so…
shbedev
  • 1,875
  • 17
  • 28
3
votes
1 answer

how do I handle subview resizing in a UITableViewCell going in & out of EDIT MODE?

QUESTION - How do I handle subview resizing in a UITableViewCell going in & out of EDIT MODE? BACKGROUND - I've worked out how to size my UiLabels & UITableViewCell based around the text & font used. I'm currently doign this in…
Greg
  • 34,042
  • 79
  • 253
  • 454
3
votes
5 answers

Overriding layoutSubviews when rotating UIView

When rotating a scroll view inside a UIView, the scroll view doesnt position correctly using its default autoresizing behaviour. Thus, when rotation occurs, in willRotateToInterfaceOrientation i call [self.view setNeedsLayout]; and my…
joec
  • 3,533
  • 10
  • 60
  • 89
3
votes
2 answers

UIScrollView doesn't update properly, shows empty view randomly

I am trying to open a new view on select of a table cell in a previous view. The new view that I am trying to open, consists of different sub-views or modules. Hence, I populate each sub-view one by one inside in [self populate] method which is in…
3
votes
1 answer

How I can round UIImageView in UICollectionViewCell?

In my UICollectionViewCell class I wrote this: - (void)layoutSubviews { [super layoutSubviews]; self.myImageView.layer.cornerRadius = CGRectGetHeight(self.myImageView.frame) / 2; self.myImageView.layer.masksToBounds = YES; } But this…
Pagly
  • 73
  • 7
3
votes
1 answer

Auto Layout still required after executing -layoutSubviews. UICollectionView's implementation of -layoutSubviews needs to call super

I use UICollectionView with default UICollectionViewFlowLayout. It works on iOS 8, but on iOS 7.1 I get Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing…
onmyway133
  • 45,645
  • 31
  • 257
  • 263
3
votes
2 answers

UITableView: How to change cell height dynamically when a button is clicked in it?

I have a UITableView, in which each cell has a button. When the button is clicked, the cell's height will be changed. Of course, the whole tableview height will be changed according to it. I cannot find a way during long surfing. What is an elegant…
ttotto
  • 826
  • 3
  • 13
  • 31
1
2
3
9 10