首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在iOS 7 GM的最后一项上,UIActionSheet未显示分隔符

在iOS 7 GM的最后一项上,UIActionSheet未显示分隔符
EN

Stack Overflow用户
提问于 2013-09-14 00:16:58
回答 5查看 12.8K关注 0票数 46

这可能是iOS7上的一个bug。但是最后一个按钮并没有与上一个按钮分开。

正如您从图像中所看到的。这在使用iOS7 GM的模拟器和设备上都会发生。其他人都有同样的问题吗?

代码语言:javascript
复制
UIActionSheet *actionSheet = [[UIActionSheet alloc]
               initWithTitle:@"Title"
               delegate:self
               cancelButtonTitle:nil
               destructiveButtonTitle:nil
               otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];

如您所见,代码非常简单。有没有办法解决这个问题?或者是我可以用来代替UIActionSheet的第三方库?

EN

回答 5

Stack Overflow用户

发布于 2013-11-08 03:22:59

我发现在初始化后添加一个带有空字符串的cancel按钮是可行的。取消按钮不会出现,分隔符会出现。

代码语言:javascript
复制
[sheet addButtonWithTitle: @""];
[sheet setCancelButtonIndex: sheet.numberOfButtons - 1];

但这只适用于iPad。在iPhone上,会出现一个空的取消按钮,但我找到了一个老生常谈的解决办法来让它正常工作。除了上述内容之外,在willPresentActionSheet中,将以下代码添加到:

代码语言:javascript
复制
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;
}];

这将使工作表向下移动以隐藏屏幕上的取消按钮

票数 6
EN

Stack Overflow用户

发布于 2014-03-22 02:02:51

最简单的解决方法是在分配期间将@""而不是nil传递给cancel按钮标题。

代码语言:javascript
复制
UIActionSheet *actionSheet = [[UIActionSheet alloc]
               initWithTitle:@"Title"
               delegate:self
               cancelButtonTitle:@"" // change is here
               destructiveButtonTitle:nil
               otherButtonTitles:@"First", @"Second", @"Third", @"Fourth", nil];
[actionSheet showInView:self.view];
票数 5
EN

Stack Overflow用户

发布于 2013-10-06 19:15:30

代码语言:javascript
复制
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];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18790868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档