[英]Getting the number pixels in width and height inside an UI Object?
Currently I do something that looks a bit fuzzy because I am dealing with points with my UI Object but what I want to do is get the width and height of the UI Object (in my case a UIImageView) in pixels. 目前,我正在做一些看起来有些模糊的事情,因为我正在用UI Object处理点,但是我想做的是以像素为单位获取UI Object(在我的情况下为UIImageView)的宽度和高度。
Is this possible? 这可能吗? I have looked around the documentation but I have not seen anything that looks relevant. 我浏览了文档,但没有发现任何相关的内容。
Can anyone assist with this? 有人可以协助吗?
Thanks! 谢谢!
Have you tried this? 你有尝试过吗?
[object frame].size.height
[object frame].size.width
I'm pretty sure that anything with a visual representation will have a frame attribute to indicate where it's located. 我很确定任何具有视觉表示的东西都将具有frame属性来指示其位置。 Of course, the origin
of an object's frame is relative to its container, but the size
should always be useable. 当然,对象框架的origin
是相对于其容器的,但size
应始终可用。
Edit/Update: 编辑/更新:
I misread the initial question, which wants to also convert points --> pixels. 我误读了最初的问题,该问题也想转换点->像素。 Here's how to make sure you get that correctly: 这是确保正确获得的方法:
float scale;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
// This message was implemented in iOS 4.0
scale = [[UIScreen mainScreen] scale];
} else {
// Anything that is running < 4.0 doesn't have a Retina display
scale = 1.0;
}
Then, multiply the height and width values by scale to get actual pixel count. 然后,将高度和宽度值乘以比例以获得实际像素数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.