滚动视图 iphone 周围的阴影或边框

Shadow or Border around a scrollview iphone(滚动视图 iphone 周围的阴影或边框)
本文介绍了滚动视图 iphone 周围的阴影或边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 uiscrollview 周围绘制边框/阴影,我知道我可以通过额外的视图或滚动视图到达那里,但不喜欢处理缺点,但我听说应该有可能直接绘制边框到滚动视图,这就是我想要的.

i would like to draw a border / shadow around a uiscrollview, i know that i could get there with an additional view or scrollview but dont like the handling an drawbacks but i heard that there should be a possibility to dirctly draw a border to a scrollview and that is what i would prefer.

我是 iphone 开发的新手,任何答案都会有所帮助.

I am quiet new to iphone developement,any answer would helpful.

推荐答案

如果您使用滚动视图(或任何 UIView)的 layer 属性,您可以轻松获得实心边框...

If you use the layer property of your scroll view (or any UIView) you can easily get a solid border...

#import <QuartzCore/QuartzCore.h>
...
myView.layer.borderWidth = 2;
myView.layer.borderColor = [UIColor blackColor].CGColor;

您也可以通过设置 layer.shadow* 属性来使用图层来应用实时阴影,但是使用此技术可能会降低性能,因此我通常更喜欢使用以下更复杂的方法,但更高效的技术.您可以创建一个中间透明、边缘有阴影的 PNG 图像 - 它需要有 9 个不同的区域:每个角 4 个,每个边缘 4 个,中间有一个完全透明的 1x1 像素区域.例如,如果您的阴影在图像中延伸 6 个像素,则您的图像将是 13x13,具有 6 像素宽/高边框和 1x1 区域在中间.然后使用以下方法将其设置为可缩放图像:

You can also use the layer to apply real-time shadows by setting the layer.shadow* properties, but performance can be slow with this technique, so I generally prefer to use the following more complex, but more performant technique. You can create a PNG image with transparency in the middle and shadows around the edge - it needs to have 9 distinct areas: 4 for each corner, 4 for each edge, and a completely transparent 1x1 pixel area in the middle. For example if your shadow extends 6 pixels into your image, your image would be 13x13 with the 6 pixel wide/high borders and the 1x1 area in the middle. Then you set it as a scalable image using:

newImage = [image stretchableImageWithLeftCapWidth:6 topCapHeight:6];

更新: 由于 iOS 5.0 stretchableImageWithLeftCapWidth:topCapHeight: 已弃用,因此仅当您仍想支持 iOS 4.x 设备时才使用此功能.如果您只想支持 iOS 5.0+ 设备,请改用:

UPDATE: Since iOS 5.0 stretchableImageWithLeftCapWidth:topCapHeight: is deprecated so only use this if you still want to support iOS 4.x devices. If you want to support only iOS 5.0+ devices use this instead:

newImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];

然后将图像放在父视图上,这样它就占据了滚动视图的整个区域.如果您希望阴影覆盖您的可滚动元素,(因此您的滚动视图看起来嵌入/位于页面的其余部分之后)然后在顶部放置一个透明的 UIView 并在其上放置阴影图像,以便它显示到您的滚动视图在它后面.

Then you put the image on the parent view so it takes up the entire area of the scroll view. If you want the shadows to go OVER your scrollable elements, (so your scroll view looks inset/behind the rest of the page) then place a transparent UIView over the top with the shadow image on it so that it shows through to your scroll view behind it.

这篇关于滚动视图 iphone 周围的阴影或边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
Android 7.0 : #39;javax.net.ssl.SSLHandshakeException: Connection closed by peer(Android 7.0:javax.net.ssl.SSLHandshakeException:连接被对等方关闭)
How to fix ‘TIC SSL Trust Error’ in iOS?(如何修复 iOS 中的“TIC SSL 信任错误?)
quot;Server certificate untrustedquot; error in iPhone application(“服务器证书不受信任iPhone应用程序中的错误)