Why does initWithFrame have the wrong frame value?

Posted by greypoint on Stack Overflow See other posts from Stack Overflow or by greypoint
Published on 2010-04-17T15:11:09Z Indexed on 2010/04/17 15:13 UTC
Read the original article Hit count: 213

Filed under:
|
|
|
|

I have a subclass of UIButton called INMenuCard and I am overriding the initWithFrame to include an activity indicator. The menuCard places correctly but any internal reference to "frame" give me "inf,inf,0,0" which means my activityIndicator subview is not placed correctly. What might I be missing?

@implementation INMenuCard

- (id)initWithFrame:(CGRect)frame 
{
    if (self = [super initWithFrame:frame]) 
    {

        CGRect innerFrame = CGRectInset(frame, 50.0f, 100.0f);
        activityIndicator = [[UIActivityIndicatorView alloc]
                             initWithFrame:innerFrame];
        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [self addSubview:activityIndicator];
    }
    return self;
}

I am instantiating INMenuCard with (debugging shows the CGRect values are correct):

 CGRect cardFrame = CGRectMake(cardX, cardStartY, cardWidth, cardHeight);
 INMenuCard *menuCard = [[INMenuCard buttonWithType:UIButtonTypeCustom] initWithFrame:cardFrame];
 [theView addSubView:menuCard];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiview