在 UITableViewCell 图像上设置 UIImage 尺寸
我有一个标准的 UITableViewCell ,我在其中使用文本和图像属性来显示 favicon.ico 和标签。 在大多数情况下,由于 UIImage
支持 ICO 格式,因此效果非常好。 但是,某些网站(例如 Amazon.com 等)有 favicon.ico
利用 ICO 格式在同一文件中存储多个大小的能力。 亚马逊存储四种不同尺寸,最大尺寸为 48x48。
这导致大多数图像都是 16x16,除了少数 32x32 或 48x48 的图像,这使得一切看起来都很糟糕。 我已经在这里、官方论坛、文档和其他地方搜索过,但没有成功。 我已经尝试了所有我能想到的来限制图像大小的方法。 唯一有效的是一种未记录的方法,我不打算使用它。 这是我的第一个应用程序,也是我第一次使用 Cocoa(来自 C#)。
如果我不清楚我在寻找什么,理想情况下建议将围绕设置 UIImage 的尺寸,以便 48x48 版本缩小到 16x16 或告诉 UIImage
的方法code>UIImage 使用 ICO 文件中存在的 16x16 版本。 我不一定需要代码:只需一个方法建议就可以了。
有没有人有什么建议? (我也在官方论坛询问,因为我已经沉迷了一天多了如果那里已经发布了解决方案,我也会将其放在这里。)
I've got a standard UITableViewCell
where I'm using the text and image properties to display a favicon.ico
and a label. For the most part, this works really well since UIImage
supports the ICO format. However, some sites (like Amazon.com say) have favicon.ico
s that make use of the ICO format's ability to store multiple sizes in the same file. Amazon stores four different sizes, all the way up to 48x48.
This results in most images being 16x16 except for a few that come in at 32x32 or 48x48 and make everything look terrible. I have searched here, the official forum, the documentation, and elsewhere without success. I have tried everything that I could think of to constrain the image size. The only thing that worked was an undocumented method, which I'm not about to use. This is my first app and my first experience with Cocoa (came from C#).
In case I wasn't clear in what I'm looking for, ideally the advice would center around setting the dimensions of the UIImage
so that the 48x48 version would scale down to 16x16 or a method to tell UIImage
to use the 16x16 version present in the ICO file. I don't necessarily need code: just a suggestion of an approach would do me fine.
Does anyone have any suggestions? (I asked in the official forum as well because I've sunk more than a day into this already. If a solution is posted there, I'll put it here as well.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以下是用户“bcd”在官方论坛发布的内容,最终解决了问题(我自己稍作修改,使其成为静态,以便包含到一组实用方法中):
Here's what user "bcd" over at the official forums posted that ended up solving the problem (with a slight modification by myself to make it static for inclusion into a set of utility methods):
我正在我的应用程序中做类似的事情。
然后创建一个限制比例的新图像。 将“image”替换为您从 Amazon 获得的 ICO 文件。
I'm doing something similar in my app.
Then create a new image constraining the proportions. Replacing "image" with the ICO file you get from Amazon.
还没有足够的业力来评论答案,但我在上面的 bbrandons 代码上取得了很好的成功。
尽管关于每行字节数设置不够高,我确实在控制台上收到了相当多的警告 - 在阅读了对此的答案 post 我最终将其设置为 0,这让系统可以确定正确的值。
例如:
Don't have enough karma yet to comment on answers, but I had good success with bbrandons code above.
I did get a fair number of warnings on the console though regarding bytes per row setting not being high enough - after reading answers to this post I ended up setting it to 0, which lets the system determine the right value.
eg:
我是这样做的。 此技术负责将文本和详细文本标签适当地向左移动:
Here's how i did it. This technique takes care of moving the text and detail text labels appropriately to the left:
我对 ico 文件如何工作一无所知,所以也许可以轻松提取 16x16 图像并使用它,但我不知道如何操作。
据我所知,不可能在通用
UITableViewCell
中的图像上设置任何有用的属性。 将所有内容缩小到 16x16 的最简单方法(仍然很混乱,特别是如果您是新手)是子类UITableViewCell
,给它一个UIImageView
,始终调整大小将图像视图设置为 16x16,并将其 contentMode 设置为 UIViewContentModeAspectFit。I don't know anything about how ico files work, so maybe it's possible to handily extract the 16x16 image and use that, but I have no idea how.
As far as I'm aware, it's not possible to set any useful properties on the image in a generic
UITableViewCell
. The simplest way (still messy, especially if you're new to it) to scale everything down to 16x16 would be to subclassUITableViewCell
, give it aUIImageView
, always size the image view to 16x16, and set its contentMode toUIViewContentModeAspectFit
.我修改了其他人的人物类别,以便使所有图像占据相同的宽度(可见宽度),而不进行缩放:
I have modified others' people category, in order to make all images occupy the same width(visible width), WITHOUT SCALING: