gklka / GKActionSheetPicker

An easy-to-use controller for presenting UIPickerView in overlay view
MIT License
25 stars 9 forks source link

Incorrect picker width #3

Open IvanDev opened 8 years ago

IvanDev commented 8 years ago

Hello gklka, Thank you for this control, I noticed layout issue on wide devices. I don't have time to make normal pull request, but here is my fix for this issue. Hope this helps someone.

In order to fix picker width issue on wide devices (e.g. iPhone 6), you need to call setNeedsLayout and layoutIfNeeded. You can fix it at GKActionSheetPicker.m: 444 so it looks like this:

// Add picker
    if (self.pickerType == GKActionSheetPickerTypeString ||
        self.pickerType == GKActionSheetPickerTypeMultiColumnString) {

        self.pickerView.frame = CGRectMake(0, ToolbarHeight, hostFrame.size.width, PickerViewHeight);
        self.pickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self.pickerContainerView addSubview:self.pickerView];

        [self.pickerView setNeedsLayout];
        [self.pickerView layoutIfNeeded];
    } else if (self.pickerType == GKActionSheetPickerTypeDate) {

        self.datePicker.frame = CGRectMake(0, ToolbarHeight, hostFrame.size.width, PickerViewHeight);
        self.datePicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self.pickerContainerView addSubview:self.datePicker];
        [self.datePicker addTarget:self action:@selector(datePickerDidChangeValue:) forControlEvents:UIControlEventValueChanged];

        [self.datePicker setNeedsLayout];
        [self.datePicker layoutIfNeeded];
    }
gklka commented 8 years ago

This does not work for me. Even the "Basic" example sticks at the previous orientation's width. :(