无论我尝试初始化 UIBarButtonItem 的图像,它都只是显示图像大小的白色背景。即使我厌倦了界面构建器,结果也是一样的。所有这些图像与其他对象一起使用时效果都很好。
我该如何解决这个问题?
最佳答案
仅使用图像中的 alpha 值来创建栏按钮图像。无论您提供什么图像,都会根据 Alpha 值转换为带有白色阴影的图像。
因此,考虑到您的图像是全白的,很明显您没有任何透明度。
guidelines有话要说:
- Use the PNG format.
- Use pure white with appropriate alpha.
- Do not include a drop shadow.
- Use anti-aliasing.
- If you decide to add a bevel, be sure that it is 90° (to help you do this, imagine a light source positioned at the top of the icon).
- For toolbar and navigation bar icons, create an icon that measures about 20 x 20 pixels.
- For tab bar icons, create an icon that measures about 30 x 30 pixels.
Note: The icon you provide for toolbars, navigation bars, and tab bars is used as a mask to create the icon you see in your application. It is not necessary to create a full-color icon.
但是,您可以使用自定义 View 来获取全彩图像,如以下问题所示:
Can I have a UIBarButtonItem with a colored image?
不过这有点过头了,最好遵循指南并使用带有适当格式图像的普通按钮。
关于iphone - UIBarButtonItem 图像未显示,而是显示图像大小的白色矩形,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2903444/