我已经研究了这个问题几个小时,对我来说听起来很简单,但一直未能找到可行的解决方案。我有一个 iPad 应用程序,我在其中使用 UIActionSheet 来确认删除。我正在添加标签以增加字体大小。一切看起来都很棒。我还需要在操作表可见时调暗并锁定背景。我可以调暗但看不到如何锁定背景,以便用户必须在操作表上进行选择才能将其关闭。我试过设置 UserInteractionEnabled 但它不起作用。有什么想法吗?
// dim the background
UIView *dimViewDelete = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
dimViewDelete.backgroundColor = [UIColor blackColor];
dimViewDelete.alpha = 0.3f;
dimViewDelete.tag = 2222;
[self.view addSubview:dimViewDelete];
if ([self.listArray count] > 0)
{
// create Action Sheet
UIActionSheet * action = [[UIActionSheet alloc]
initWithTitle:@" "
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete"
otherButtonTitles:nil];
[action addButtonWithTitle:@"Cancel"];
[action setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[action showInView:self.view];
// change the font size of the title
CGRect oldFrame = [(UILabel*)[[action subviews] objectAtIndex:0] frame];
UILabel *addTitle = [[UILabel alloc] initWithFrame:oldFrame];
addTitle.font = [UIFont boldSystemFontOfSize:22];
addTitle.textAlignment = UITextAlignmentCenter;
addTitle.backgroundColor = [UIColor clearColor];
addTitle.textColor = [UIColor whiteColor];
addTitle.text = @"Are You Sure?";
[addTitle sizeToFit];
addTitle.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y,
oldFrame.size.width, addTitle.frame.size.height);
[action addSubview:addTitle];
}
最佳答案
您最好的选择是实现您自己的自定义操作表式控件。
您需要一个简单的 View Controller ,它有两个按钮和一个标签(用于标题)。在弹出窗口中显示 View Controller 。使 View Controller 成为模态,因此只能通过点击其中一个按钮将其关闭。这也会使背景显得锁定。
如果你真的需要调暗背景,就在显示弹出窗口之前,向主窗口添加一个屏幕大小的UIView
。将此 View 的背景设置为 [UIColor whiteColor:0 alpha:0.7]
。根据需要调整 alpha 以获得正确的调光效果。您甚至可以为 View 的 alpha 设置动画,使其根据需要淡入淡出。
关于ios - 在 iPad 上使用 UIActionSheet 时调暗并锁定背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14143973/