Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Graceful fallback if no buttons are provided #4

@nothine

Description

@nothine

Hi,
when working with DDExpandableButton (which is a great entrypoint by the way) I stumbled upon the non-obvious behaviour when you only want to present an image with toggleMode:YES and no "buttons". This is interesting if all you want to show is the image in leftTitle.
First of all, initWithPoint:leftTitle:buttons: can't handle either nil or an empty NSArray as input for buttons. A quick fix would be

if ([buttons count])

in setButtons: before adding to _labels.
But the tricky part only comes then :-) With a @"" as button and a normal 20x20 image in leftTitle, the whole DDExpendableButton is suddenly only 20 pixels in width total. The only way I found visually pleasing working was to quickly whip up an empty view with a width of 18px like so:

@interface EmptyView : UIView 
+ (id)emptyView;
@end

@implementation EmptyView

- (CGSize)defaultFrameSize
{
    return self.bounds.size;
}
- (CGFloat)defaultFrameWidth
{
    return CGRectGetWidth(self.bounds);
}
- (id)init
{
    return [self initWithFrame:CGRectZero];
}
+ (id)emptyView
{
    return [[self alloc] init];
}

@end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions