小智 408
let heightInPoints = image.size.height
let heightInPixels = heightInPoints * image.scale
let widthInPoints = image.size.width
let widthInPixels = widthInPoints * image.scale
Run Code Online (Sandbox Code Playgroud)
Sal*_*lim 11
UIImage *img = [UIImage imageNamed:@"logo.png"];
CGFloat width = img.size.width;
CGFloat height = img.size.height;
Run Code Online (Sandbox Code Playgroud)
小智 6
上面的某些固定装置在旋转设备时无法正常工作。
尝试:
CGRect imageContent = self.myUIImage.bounds;
CGFloat imageWidth = imageContent.size.width;
CGFloat imageHeight = imageContent.size.height;
Run Code Online (Sandbox Code Playgroud)
有很多有用的解决方案,但没有简化的扩展方法。这是通过扩展解决问题的代码:
extension UIImage {
var getWidth: CGFloat {
get {
let width = self.size.width
return width
}
}
var getHeight: CGFloat {
get {
let height = self.size.height
return height
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151924 次 |
| 最近记录: |