我有一个 UITableViewController
,其中 UITableViewCell
是动态的并且继承自自定义 UITableViewCell
类。我在单元格上引入了滑动手势来收藏该单元格,但我对滑动单元格时显示的图像有一些问题。
这是它目前的样子:
除了 iPhone 5s,它看起来像素化且糟糕。该图片当前是大小为 50x50 的方形图片。
如果我将尺寸增加到 200x200,我得到:
这看起来像素化程度较低,但同时看起来绝对糟糕。
在我的 cellForRow
中,这是我用来应用图像的代码:[self.rightUtilityButton sw_addUtilityButtonWithColor:
[UIColor orangeColor] icon:[UIImage imageNamed:@"Star.png"]];
我正在使用 SWTableViewCell 开源代码 ( https://github.com/CEWendel/SWTableViewCell ) 作为我对此的引用,但我无法在代码中找到在 UITableViewCell 自定义图像上实际设置此大小的位置,我无法取得联系与作者。
问题
我基本上想使用200x200 图像,但在50x50 图像的框架尺寸中。我怎么能强制这个?也许我可以将 200x200 图像放入另一个背景清晰的 UIImageView
中?如果那样的话,我不确定如何实现它。任何指导将不胜感激。
最佳答案
您应该为同一图像包含多个分辨率并使用@nx 命名方案。
例如:您在界面生成器或代码中将 imageView 设置为 50 x 50 像素。 对于上述 imageView,您应该提供以下图像:
star.png - 50x50 px (For screens with scale 1 resolution like in iPhone 3GS, iPad 2)
star@2x.png - 100x100 px (For screens with scale 2 resolution like in iPhone 4s - iPhone 6)
star@3x.png - 150x150 px (For screens with scale 3 resolution like in iPhone 6S)
然后,只需将 imageView 的图像设置为:
[imageView setImage:@"star"]; //Dont use the extension
此时,应用会根据当前屏幕自动选取最佳图片并显示正确的图片。
关于ios - 在 UITableViewCell 中使用高分辨率图像进行自定义滑动机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33970554/