我的网页中有一个宽度为“50px”、高度为“40px”的图像。
现在我想在 UIImageView 中显示相同尺寸的图像。
如何将像素转换为 CGFloat?
感谢您的回答。
最佳答案
你可以像这样创建它:
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
);
关于iphone - 如何将像素转换为CGFloat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674208/