문제

I'm trying to subclass a UIToolbar but the code doesn't seem to be working when I add the class to a UIToolbar in Interface Builder. What am I doing wrong here? I'm also looking for adding UIBarbuttonitems etc., this is just a test eg., daniel

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

        //Customization//
        UIImage *ToolbarBackgroundImage;
        ToolbarBackgroundImage = [UIImage imageNamed:@"DefaultNavBar"];

        [self setBackgroundImage:ToolbarBackgroundImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];

        [self setShadowImage:[[UIImage alloc] init] forToolbarPosition:UIToolbarPositionAny];

    }
    return self;
}

-(void)drawRect:(CGRect)rect {

    //do nothing//
}
도움이 되었습니까?

해결책

If you are using a storyboard, you should also implement initWithCoder:.

When a storyboard is being loaded, a decoder is used to create objects defined in the storyboard. initWithCoder: comes from the NSCoding protocol, and is a way for classes to deserialize themselves from coders. You can read about it in detail here.

If you wish to support both nibs and storyboards, there is a method available you can implement in your views, awakeFromNib.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top