iOS 8 Custom label LayoutSubviews method never get called?

918 views Asked by At

XCODE 6.0.1, IOS 8, Custom UILabel, Method: LayoutSubviews

I have custom UILabel which works fine on iOS6 and iOS7. But on iOS 8 this label's -(void)layoutSubviews method never get called. Here I would like to add that label is part of my storyboard scene and it was created in previous Xcode version.

What happens with autoLayout system in iOS 8? Is there any major change related to view layout?

Any help is appreciated.

Thanks.

1

There are 1 answers

0
iosdev1111 On

Check answer to this question:Xcode6, iOS8 and (void)layoutSubviews

Really layoutSubviews is not called anymore for UILabel on iOS8, as Apple does not expect anybody uses it as superview.

I am using ReactiveCocoaLayout, so it can be done by subscribing to rcl_frameSignal or rcl_boundsSignal.

-(void)awakeFromNib { [ self.rcl_boundsSignal subscribeNext: ^( NSValue* boundsValue ) { //layout changed } ]; }
Or you can use simple KVO to know when frame has been changed:
-(void)dealloc
{
   [ self removeObserver: self forKeyPath: @"layer.bounds" ];
}

-(void)observeValueForKeyPath:( NSString* )keyPath
                     ofObject:( id )object
                       change:( NSDictionary* )change
                      context:( void* )context
{
   if ( [ keyPath isEqualToString: @"layer.bounds" ] )
   {
      //layoutSubviews
   }
   else
   {
      [ super observeValueForKeyPath: keyPath
                      ofObject: object
                        change: change
                       context: context ];
   }
}

-(void)awakeFromNib
{
   [ self addObserver: self
           forKeyPath: @"layer.bounds"
              options: NSKeyValueObservingOptionNew
              context: 0 ];
}