ios - iOS 中的图像拉伸(stretch)不正确

标签 ios objective-c

<分区>

存在以下问题:我使用 UIImage,当我以编程方式创建它而不设置图像大小时,我的图像在垂直方向拉伸(stretch)时出现一些问题。看截图:

enter image description here

我的代码是:

[backButton setBackButtonBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

我还有同名但前缀为“@2x”的图像。这可能是什么麻烦?

最佳答案

尝试为 UINavigationBar 设置 Back Indicator Image,而不是为 UIBarButtonItem 设置 BackButtonBackgroundImage

[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn.png"]];

图像的颜色由 tintColor 属性控制。

或者使用

[[UIImage imageNamed:@"back_btn.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

关于ios - iOS 中的图像拉伸(stretch)不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21303749/

上一篇:ios - UItableView Cell Resuablity 数据在滚动时被交换

下一篇:ios - UIFont 自定义样式设置

相关文章:

c++ - 如何在 XCode 4 中将旧式构建日志设置为默认构建错误 View

ios - 在 iOS 上的 Safari 共享扩展中获取 SLComposeServiceViewController 中的 URL

ios - 使用自动布局将 UIButtons 设置为等距离

iphone - 在 didSelectRowAtIndexPath 上显示加载图像

php - 如何从ios正确上传大文件?

iphone - PCM到WAV文件

ios - 如何在 ios 中为 TableView 单元格设置圆角半径

iphone - 为什么我的 .aif 短声音文件只能在 iOS 模拟器上播放,而不能在设备上播放?

objective-c - 在 iPad 应用程序中隐藏 UITabBar

ios - 无法将 UIViewController 限制为仅纵向