maxkonovalov / MKDropdownMenu

🔻 Dropdown Menu for iOS with many customizable parameters to suit any needs
MIT License
524 stars 83 forks source link

widthForComponent not setting desired width #19

Open serjooo opened 7 years ago

serjooo commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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.