Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widthForComponent not setting desired width #19

Open
serjooo opened this issue Mar 6, 2017 · 4 comments
Open

widthForComponent not setting desired width #19

serjooo opened this issue Mar 6, 2017 · 4 comments

Comments

@serjooo
Copy link

serjooo commented Mar 6, 2017

I am attempting to set a custom width for devices > 375 technically ipads to take a specific amount of width but not matter the width I return the drop down menu's width stays at I guess the default size. In addition, I have set the setUseFullScreenWidth to NO on viewDidLoad, if that makes any difference. This is the code I am using and a screenshot of the simulator on ipadAir2 is attached as well

- (CGFloat)dropdownMenu:(MKDropdownMenu *)dropdownMenu widthForComponent:(NSInteger)component {
    if(self.view.frame.size.width > 375) {
        [dropdownMenu setUseFullScreenWidth:NO];
        return 100.0;
    } else {
        [dropdownMenu setUseFullScreenWidth:YES];
        return 0;
    }
}

simulator screen shot mar 6 2017 1 50 40 pm

@maxkonovalov
Copy link
Owner

Hi @serjooo!

If I understood your setup correctly, you have 2 components in your menu.

The width for components is calculated left-to-right. If you provide the same value for all components and the total view width is greater than the sum of all components' widths, then the last (right-most) component will take the rest of the space, ignoring the specified number.

To work around this issue, you can specify the exact width for the desired component and set automatic width for the others:

- (CGFloat)dropdownMenu:(MKDropdownMenu *)dropdownMenu widthForComponent:(NSInteger)component {
    if (self.view.frame.size.width > 375) {
        [dropdownMenu setUseFullScreenWidth:NO];
        return component == 1 ? 100.0 : 0.0;
    } else {
        [dropdownMenu setUseFullScreenWidth:YES];
        return 0;
    }
}

Also, you can take a look at the following delegate method:

/// Return NO if the component is used as a dummy space for other components 
/// and should not be interacted with. The disclosure indicator is hidden 
/// for such components. Default = YES.
- (BOOL)dropdownMenu:(MKDropdownMenu *)dropdownMenu enableComponent:(NSInteger)component;

In case you need some specific layout for your menu, you can add some empty components.

Hope this helps 🙂

@serjooo
Copy link
Author

serjooo commented Apr 29, 2017

Hello,

Sorry I'm late for replying, got really busy and had found a different workaround for this. However, the setup you thought I have is wrong. I have One component and this component I was attempting at giving it different widths according to screen size. However, no matter the size I return, the width of the component was staying at the default size set in the class.

@maxkonovalov
Copy link
Owner

@serjooo I tried to reproduce your issue with one component, but it all worked as expected. The device screen size also didn't matter.
Did you have any issues with implementing the same thing with the Demo app? If you provide more details on your menu setup, I'd be happy to help.

@coolcool1994
Copy link

coolcool1994 commented Sep 15, 2017

I can confirm this bug. I set the width as below, and in iPhone SE it takes over the whole width. The funny thing is in iPhone 6, it the margins work. But in iPhone SE, it is full width no matter what value I set this to.

  • (CGFloat)dropdownMenu:(MKDropdownMenu *)dropdownMenu widthForComponent:(NSInteger)component {
    return CGRectGetWidth([UIScreen mainScreen].bounds)-32.0;
    } -> dropdown is still the whole width (only in iPhone SE tho)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants