如何从UIWebView中删除渐变 - 如果您过度滚动顶部或底部,则会看到渐变。 这段代码
webView.backgroundColor = [UIColor whiteColor];
只是更改渐变的颜色,它不会删除它。怎么办呢?
(注意:与UIWebView underside不同的问题)
答案 0 :(得分:82)
{
webView.backgroundColor = [UIColor whiteColor];
for (UIView* subView in [webView subviews])
{
if ([subView isKindOfClass:[UIScrollView class]]) {
for (UIView* shadowView in [subView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
}
}
答案 1 :(得分:3)
透明UIWebView并删除滚动条。
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
for(UIView *view in webView.subviews){
if ([view isKindOfClass:[UIImageView class]]) {
// to transparent
[view removeFromSuperview];
}
if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *sView = (UIScrollView *)view;
for (UIView* shadowView in [sView subviews]){
//to remove shadow
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
}
答案 2 :(得分:2)
你的意思是影子? Remove UIWebView Shadow?
答案 3 :(得分:1)
我发现如何做到这一点的唯一方法是:
for(UIView *aView in [[[webView subviews] objectAtIndex:0] subviews]) {
if([aView isKindOfClass:[UIImageView class]]) { aView.hidden = YES; }
}
它只是逐步浏览UIWebView的子视图,如果是图像视图则删除视图。
我没有将它放在任何App Store应用程序中,因此我不知道Apple是否会接受它。
编辑:Brian的链接提供了更多详细信息。
答案 4 :(得分:0)
使用上面建议的方法,您将无法在以后编辑滚动指示符/插入内容。它们也显示为UIImageView,因此您应该检查最后一个对象:
UIView* lastView = [[subView subviews] lastObject];
for (UIView* shadowView in [subView subviews])
{
if(shadowView!=lastView) ... <-this one is a scroll
}
答案 5 :(得分:0)
我能够通过在WebView的scrollView的顶部和底部添加白色子视图来实现此目的。我控制WebView的内容,所以我知道白色是可以的 - 如果你加载任意内容,这将不起作用。
// _topCover and _bottomCover are ivar UIViews
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// with cover views 300pt high, I couldn't scroll far enough to see the shadow,
// even in portrait on an iPad, which gives you the longest scroll distance
CGFloat coverage = 300;
_topCover = [[UIView alloc] initWithFrame:CGRectMake(0, -coverage, webView.bounds.size.width, coverage)];
_bottomCover = [[UIView alloc] initWithFrame:CGRectMake(0, webView.scrollView.contentSize.height, webView.bounds.size.width, coverage)];
_topCover.backgroundColor = [UIColor whiteColor];
_bottomCover.backgroundColor = [UIColor whiteColor];
// in case the webView is resized, e.g. by rotating the device
_topCover.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
_bottomCover.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[webView.scrollView addSubview:_topCover];
[webView.scrollView addSubview:_bottomCover];
}
我在页面加载后运行它,以便webView.scrollView.contentSize.height
给我正确的高度。如果您的页面动态改变高度,我不确定这将如何工作。我的页面只加载一次;如果您正在重新加载,则需要在第一次之后跳过在alloc
和init
上运行_topCover
/ _bottomCover
以提高效率。
更新:我不确定在视图旋转时,我在上面使用autoresizingMask
是否足够。您可能需要将此内容放在包含UIViewController
的{{1}}中,以便在旋转后调整封面大小:
UIWebView
答案 6 :(得分:0)
我建立在@damithH的回答
之上@implementation UIWebView (Extensions)
- (void)setBackgroundAndShadowVisible:(BOOL)visible
{
self.opaque = !visible;
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:visible ? 1.0 : 0.0];
for(UIView *view in [self subviews])
{
if([view isKindOfClass:[UIImageView class]])
{
view.hidden = !visible;
}
if([view isKindOfClass:[UIScrollView class]])
{
UIScrollView *scrollView = (UIScrollView *)view;
for (UIView *shadowView in [scrollView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]])
{
shadowView.hidden = !visible;
}
}
}
}
}
@end
答案 7 :(得分:0)
if (UIDevice.currentDevice.systemVersion.intValue < 7)
for (UIImageView *imageView in webView.scrollView.subviews)
if ([imageView isKindOfClass:[UIImageView class]] && imageView.image.size.width == 1)
imageView.hidden = YES;