Objective c 无背景着色的UIActionSheet
所以我读过 但它似乎没有处理使背景不着色为半透明的问题。我希望菜单后面的内容和按钮清晰可见。这可能吗 这就是我目前拥有的Objective c 无背景着色的UIActionSheet,objective-c,ios,uiview,transparent,uiactionsheet,Objective C,Ios,Uiview,Transparent,Uiactionsheet,所以我读过 但它似乎没有处理使背景不着色为半透明的问题。我希望菜单后面的内容和按钮清晰可见。这可能吗 这就是我目前拥有的 WPSActionSheet *actionSheet = [[WPSActionSheet alloc] initWithCompletion:completion]; [actionSheet setTitle:@""]; [actionSheet addButtonWithTitle:@"Take Photo"]; [actionSheet addButto
WPSActionSheet *actionSheet = [[WPSActionSheet alloc] initWithCompletion:completion];
[actionSheet setTitle:@""];
[actionSheet addButtonWithTitle:@"Take Photo"];
[actionSheet addButtonWithTitle:@"Choose from Library"];
[actionSheet addButtonWithTitle:@"Skip This Step"];
[actionSheet setCancelButtonIndex:2];
[actionSheet showInView:[self view]];
这说明了这一点
UIActionSheet将始终显示“着色背景”。这是没有办法的。但是,您可以使用
UIView
创建自己版本的UIActionSheet
,只需使用委托方法设置UIActionSheet的alpha和不透明属性-
(void)willPresentActionSheet:(UIActionSheet *)actionSheet
并且它将根据您的需要显示。如果您想使UIActionSheet的背景透明,您可以将其子类化并更改LayoutSubView
- (void)layoutSubviews
{
[super layoutSubviews];
UIImage* image;
CGSize size = self.frame.size;
UIGraphicsBeginImageContext(size);
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[self layer] setContents:(id)image.CGImage];
}
要添加一些自定义背景,只需将以下代码添加到LayoutSubView:
CGRect frame = self.frame;
frame.origin = CGPointZero;
UIImageView* bg = [[UIImageView alloc] initWithFrame:frame];
bg.image = [UIImage imageNamed@"YOUR/IMAGE/NAME"];
[self addSubview:bg];
[self sendSubviewToBack:bg];
您还可以在委托方法中执行所有这些操作
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
简单地将self替换为actionSheet我也遇到了同样的问题,并找到了解决办法。
ui操作表
的超级视图包含一个用于着色的ui视图
。因此,可以通过将此视图图层的不透明度设置为0来删除着色
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
NSArray *subviews = actionSheet.superview.subviews;
UIView *tintView = [subviews objectAtIndex:0];
[tintView.layer setOpacity:0.0];
}
你是说你希望完全消除按钮周围的背景吗?他们看起来会不会有点奇怪。。。挂在那里?或者你正在尝试做其他事情?不是按钮周围的背景,而是“从添加个人资料图像开始”结束的着色背景。谢谢!很高兴有一个明确的是或不是。这已经困扰了我好几天了!实施你所说的有多难?试着决定是否值得付出努力。创建自己的应该不会太难。您可以随时在google上搜索,看看是否有一个开源类可以用来复制
UIActionSheet
。非常感谢您的帮助。我看看能找到什么。这太冒险了哈哈:o-在iOS8测试版中不起作用5@AlbertRenshaw它与iOS 7一起工作。在iOS 8中,UIActionSheet
将nil
作为其superview
返回。因此,我的方法行不通。