Pun*_*nty 46 iphone uikit uiactionsheet ios ios7
这可能是iOS7上的一个错误.但是最后一个按钮与前一个按钮没有分开
从图像中可以看出.使用iOS7 GM在Simulator和设备上都会发生这种情况.其他人都有同样的问题吗?
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Title"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,代码非常简单.有关如何解决问题的任何想法?或者我可以使用一些第三方库而不是UIActionSheet?
Yid*_*ing 24
我认为ActionSheet 需要一个取消按钮.所以你可以添加取消按钮标题.
另一种方法是:指定actionSheet的cancelButtonIndex.
例如,在您的情况下,您可以在索引4处的otherButtonTitles中添加" Cancel ",然后指定 actionSheet.cancelButtonIndex = 4.
我找到了一种方法,可以用最简单的方式使它在iPhone和iPad上运行:
我假设丢失的分隔符是由首先添加或通过init添加取消按钮时不被识别为单独的情况引起的.
我发现初始化后添加一个带空字符串的取消按钮.取消按钮不会显示,分隔符显示.
[sheet addButtonWithTitle: @""];
[sheet setCancelButtonIndex: sheet.numberOfButtons - 1];
Run Code Online (Sandbox Code Playgroud)
但这仅适用于iPad.在iPhone上,显示一个空取消按钮,但我发现了一个hacky解决方法,使其工作.除上述内容外,在willPresentActionSheet此处添加以下代码:
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;
}];
Run Code Online (Sandbox Code Playgroud)
这会向下移动工作表以隐藏屏幕上的取消按钮
最简单的解决方法是传递@""给取消按钮标题而不是nil分配期间.
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Title"
delegate:self
cancelButtonTitle:@"" // change is here
destructiveButtonTitle:nil
otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12477 次 |
| 最近记录: |