views:

118

answers:

0

I've created a UIButton subclass so that I can stick a custom view into a standard toolbar button. All it does, is create a stretchable image for the background, and then adds a custom view with userInteractionEnabled set to NO so the button handles all clicks. The code is here:

- (id) init {
    if (!(self = [super init])) {
        return self;
    }

    self.frame = CGRectMake(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
    self.bounds = CGRectMake(self.bounds.origin.x, self.bounds.origin.y + 6, self.bounds.size.width, self.bounds.size.height);

    // Buttons look best when their content is centered.
    self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    UIImage *image = [UIImage imageNamed:@"UIButtonBarMiniButton.png"];
    image = [image stretchableImageWithLeftCapWidth:5 topCapHeight:0];
    [self setBackgroundImage:image forState:UIControlStateNormal];

    image = [UIImage imageNamed:@"UIButtonBarMiniButtonPressed.png"];
    image = [image stretchableImageWithLeftCapWidth:5 topCapHeight:0];
    [self setBackgroundImage:image forState:UIControlStateHighlighted];
    self.adjustsImageWhenHighlighted = NO;

    self.backgroundColor = [UIColor clearColor];

    // *SNIP* Create custom view and add as subView
}

The button works just fine except that the clickable region doesn't include anywhere to the right of the custom view. Left of the view works fine, as well as clicking on the view, but clicking to the right doesn't register at all. What could cause this?