반응형
UI 이미지의 높이와 너비를 확인하려면 어떻게 해야 합니까?
메일의 URL 이미지에서
메일 보기에 이미지를 추가하는 중입니다.전체 이미지가 표시됩니다.하지만 이미지의 높이와 폭을 비례적으로 변화시켜 계산하고 싶습니다.
의 높이와 폭을 얻으려면 어떻게 해야 합니까?UIImage
?
let heightInPoints = image.size.height
let heightInPixels = heightInPoints * image.scale
let widthInPoints = image.size.width
let widthInPixels = widthInPoints * image.scale
를 사용합니다.size
속성을 지정합니다.상세한 것에 대하여는, 메뉴얼을 참조해 주세요.
UIImage *img = [UIImage imageNamed:@"logo.png"];
CGFloat width = img.size.width;
CGFloat height = img.size.height;
위의 일부 Anwers는 장치를 회전할 때 제대로 작동하지 않습니다.
시험:
CGRect imageContent = self.myUIImage.bounds;
CGFloat imageWidth = imageContent.size.width;
CGFloat imageHeight = imageContent.size.height;
유용한 솔루션은 많이 있지만 확장 기능을 통해 단순화할 수 있는 방법은 없습니다.확장자를 사용하여 문제를 해결하는 코드는 다음과 같습니다.
extension UIImage {
var getWidth: CGFloat {
get {
let width = self.size.width
return width
}
}
var getHeight: CGFloat {
get {
let height = self.size.height
return height
}
}
}
UIImageView *imageView = [[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"MyImage.png"]]autorelease];
NSLog(@"Size of my Image => %f, %f ", [[imageView image] size].width, [[imageView image] size].height) ;
import func AVFoundation.AVMakeRect
let imageRect = AVMakeRect(aspectRatio: self.image!.size, insideRect: self.bounds)
x = imageRect.minX
y = imageRect.minY
let imageView: UIImageView = //this is your existing imageView
let imageViewHeight: CGFloat = imageView.frame.height
let imageViewWidth: CGFloat = imageView.frame.width
언급URL : https://stackoverflow.com/questions/5249664/how-can-i-get-the-height-and-width-of-an-uiimage
반응형
'source' 카테고리의 다른 글
신뢰할 수 있는 옵션이 없는 iOS9 신뢰할 수 없는 엔터프라이즈 개발자 (0) | 2023.04.09 |
---|---|
Java에서 맵을 목록으로 변환하려면 어떻게 해야 합니까? (0) | 2023.04.09 |
추적되지 않은 파일 목록에 .gitignore가 표시되지 않도록 하려면 어떻게 해야 합니까? (0) | 2023.04.09 |
구텐베르크의 "문서" 아래에 새 패널을 추가하는 방법 (0) | 2023.04.04 |
AngularJs "controller as" 구문 - 설명? (0) | 2023.04.04 |