【发布时间】:2011-10-24 18:12:33
【问题描述】:
我可以通过这种方式为 CALayer 添加边框:
[webView.layer setBorderColor: [[UIColor colorWithRed:0.6 green:0.7 blue:0.2 alpha:1] CGColor]];
[webView.layer setBorderWidth: 2.75];
但是可以只在一侧添加边框吗?我只需要底部的边框。或者我可以通过其他属性来达到这个目的,例如框架、边界、掩码、...?
感谢您的帮助!
@Control-V
UIWebView *webView = [[UIWebView alloc] init];
CALayer *webViewLayer = webView.layer;
// now you can do a lot of stuff like borders:
[webViewLayer setBorderColor: [[UIColor greenColor] CGColor]];
[webViewLayer setBorderWidth: 2.75];
查看 CALayer 文档: https://developer.apple.com/documentation/quartzcore/calayer
看看这里: http://iosdevelopertips.com/cocoa/add-rounded-corners-and-border-to-uiwebview.html
【问题讨论】:
-
我仍然想知道您是如何找到 UIWebView 的图层属性的。我在苹果官方文档中很难找到。
-
@Control-V:我为你编辑我的问题
-
你在劫持 webview 的层?? 这是一个可怕的想法。请不要那样做。除非在极少数情况下,您应该始终将
UIWebView视为一个不可自省且完全不透明的对象。甚至不要试图乱搞诸如它的层之类的东西(因为它的层不是CALayer,而是CATiledLayer,例如),因为UIWebView可以非常特别地说明事情应该如何进行配置。
标签: iphone objective-c core-animation calayer