gpt4 book ai didi

iphone - ImageView 弃用方法

转载 作者:行者123 更新时间:2023-11-28 20:26:40 25 4
gpt4 key购买 nike

content stretch 属性在 iOS 6.0 中已被弃用,我找不到合适的替代方法。

以下是在 iOS 6.0 中有效但已弃用的代码:

UIImageView *sectionsSeparator = [[UIImageView alloc] initWithFrame:CGRectMake(x, 0, separatorWidth, totalHeight)];
sectionsSeparator.image = [self imageForSectionsSeparator];
sectionsSeparator.contentStretch = CGRectMake(0, 0.25f, 1, 0.5f);
[self addSubview:sectionsSeparator];

我尝试了下面的代码,但图像没有正确排列:

UIImageView* sectionsSeparator = [[UIImageView alloc] initWithFrame:CGRectMake(x, 0, separatorWidth, totalHeight)];
[sectionsSeparator setImage:[[self imageForSectionsSeparator] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 0.25f, 1.0f, 0.5f)]];
[overlayView addSubview:sectionsSeparator];

也许我遗漏了什么,有什么建议吗?

最佳答案

被弃用并不意味着它停止工作,它只是意味着你应该更喜欢一个替代方案,但旧的方式仍然有效。

无论如何,如果你想避免弃用的东西,你可以创建一个在文档中指定的可拉伸(stretch)图像:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/DeprecationAppendix/AppendixADeprecatedAPI.html

编辑:

cap inset 方法与 content stretch 方法相反(它向后工作)。在内容拉伸(stretch)上,你用一个矩形覆盖你想要拉伸(stretch)的内容,这是一个例子:

http://j0ris.tumblr.com/post/7345178587/uiview-contentstretch

然而,在 resizableImageWithCapInsets 上,您覆盖了您想要拉伸(stretch)的内容。

During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the pixel area not covered by the cap in each direction is tiled, left-to-right and top-to-bottom, to resize the image.

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/instm/UIImage/resizableImageWithCapInsets :

所以你应该制作不同的插图。

关于iphone - ImageView 弃用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13676138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com