【问题标题】:How to convert to pixels to CGFloat?如何将像素转换为 CGFloat?
【发布时间】:2013-07-16 10:31:26
【问题描述】:

我的网页中有一个宽度为“50px”、高度为“40px”的图像。

现在我想在 UIImageView 中显示相同尺寸的图像。

如何将像素转换为 CGFloat?

感谢您的回答。

【问题讨论】:

  • 50.0 和 40.0 还是我不理解你的问题?
  • 是的,它是 50.0 和 40.0

标签: iphone ios objective-c uiimageview cgfloat


【解决方案1】:

你可以这样创建它:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, 50.0, 40.0)];

NSString *imageURL = @"www.YourURLHere.com/YourPicture.jpg";

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]];

imageView.image = [UIImage imageWithData:imageData];

CGFloat 值与像素具有 1 对 1 的关系。

因此 100 x 100 像素应该是 100 x 100 的 CGRect,例如:

CGRect CGRectMake (
   CGFloat x,
   CGFloat y,
   CGFloat width,
   CGFloat height
);

【讨论】:

  • CGFloat(100,100)?那应该做什么?你在想CGSize(100.0, 100.0)吗?
  • 你是对的!不,我在想 CGPointMake!现在改了。
  • 请注意,在 iOS 中,基本单位是“点”,而不是像素。视网膜上的一个非常重要的区别。
猜你喜欢
  • 2010-11-06
  • 1970-01-01
  • 1970-01-01
  • 2016-10-22
  • 1970-01-01
  • 1970-01-01
  • 2011-10-15
  • 2014-07-31
  • 1970-01-01
相关资源
最近更新 更多