Loading a UIView subclass from NIB size issues

前端 未结 1 1717
广开言路
广开言路 2020-12-15 09:37

I have a subclass of UIView that needs to calculates it\'s height according to it\'s width. When created in code everything works. However when I try to create the view in I

相关标签:
1条回答
  • 2020-12-15 10:02

    If you extend initWithCoder, be sure to call the super method. It is during this super call that setFrame will be called on your class.

    You can then re-use your standard initWithFrame call.

    I always do the following:

    - (id)initWithCoder:(NSCoder *)aDecoder {
        self = [super initWithCoder:aDecoder]; // Required. setFrame will be called during this method.
        return [self initWithFrame:[self frame]];
    }
    
    0 讨论(0)
提交回复
热议问题