这可能是iOS7上的一个bug。但是最后一个按钮并没有与上一个按钮分开。
正如您从图像中所看到的。这在使用iOS7 GM的模拟器和设备上都会发生。其他人都有同样的问题吗?
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Title"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];
如您所见,代码非常简单。有没有办法解决这个问题?或者是我可以用来代替UIActionSheet的第三方库?
发布于 2013-11-08 03:22:59
我发现在初始化后添加一个带有空字符串的cancel按钮是可行的。取消按钮不会出现,分隔符会出现。
[sheet addButtonWithTitle: @""];
[sheet setCancelButtonIndex: sheet.numberOfButtons - 1];
但这只适用于iPad。在iPhone上,会出现一个空的取消按钮,但我找到了一个老生常谈的解决办法来让它正常工作。除了上述内容之外,在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;
}];
这将使工作表向下移动以隐藏屏幕上的取消按钮
发布于 2014-03-22 02:02:51
最简单的解决方法是在分配期间将@""
而不是nil
传递给cancel按钮标题。
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Title"
delegate:self
cancelButtonTitle:@"" // change is here
destructiveButtonTitle:nil
otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];
发布于 2013-10-06 19:15:30
UIActionSheet *asAccounts = [[UIActionSheet alloc]
initWithTitle:Localized(@"select_an_account")
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles: nil];
for (int i=0; i<[result count]; i++) {
ACAccount *acct = [result objectAtIndex:i];
[asAccounts addButtonWithTitle:[acct username]];
asAccounts.tag = i;
}
[asAccounts addButtonWithTitle:Localized(@"Cancel")];
asAccounts.cancelButtonIndex = result.count;
[asAccounts showInView:self.view];
https://stackoverflow.com/questions/18790868
复制相似问题