UIActionSheet is not showing separator on the last item on iOS 7 GM

后端 未结 8 485
暗喜
暗喜 2020-12-03 04:31

It could be probably a bug on iOS7. But the last button is not separated from the previous one\"UIActionSheet

8条回答
  •  生来不讨喜
    2020-12-03 04:52

    I found that adding a cancel button with an empty string after initialization works. The cancel button won't show up and the separator shows up.

    [sheet addButtonWithTitle: @""];
    [sheet setCancelButtonIndex: sheet.numberOfButtons - 1];
    

    But this only works for iPad. On iPhone, an empty cancel button shows up, but I found a hacky workaround to make it work. In addition to the above, in willPresentActionSheet add this code in:

    NSInteger offset = 55;
    CGRect superFrame = actionSheet.superview.frame;
    superFrame.origin.y += offset;
    [actionSheet.superview setFrame: superFrame];
    
    // hide underlay that gets shifted with the superview
    [(UIView*)[[actionSheet.superview subviews] objectAtIndex: 0] removeFromSuperview];
    
    // create new underlay
    CGRect underlayFrame = CGRectMake(0, -offset, superFrame.size.width, superFrame.size.height);
    UIView* underlay = [[UIView alloc] initWithFrame: underlayFrame];
    underlay.alpha = 0.0f;
    [underlay setBackgroundColor: [UIColor colorWithWhite: 0.0f alpha: 0.4f]];
    [actionSheet.superview insertSubview: underlay atIndex: 0];
    
    // simulate fade in
    [UIView animateWithDuration: 0.3f animations:^{
        underlay.alpha = 1.0f;
    }];
    

    This shifts down the sheet to hide the cancel button off the screen

提交回复
热议问题