setBackgroundImage forBarMetrics +缩放填充?

发布于 2024-12-15 03:37:54 字数 477 浏览 4 评论 0原文

从 iOS5 开始,您应该通过 setBackgroundImage forBarMetrics 设置工具栏或导航栏的背景图像。

在 iOS4 中,我使用:

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

在 iOS4 中,图像“缩放以填充”;在 iOS5 中,如果图像太小,则会重复图像。当您使用 setBackgroundImage forBarMetrics 时,有没有办法将行为设置为“scaleToFill”?

谢谢!

Since iOS5 you should set the backgroundimage of tool- or navigationbars via setBackgroundImage forBarMetrics.

In iOS4 I use:

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

In iOS4 the image "scales to fill" in iOS5 the image is repeated if it's to small. Is there a way to set the behaviour to "scaleToFill" when you use setBackgroundImage forBarMetrics?

Thx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文