나는 엑스 코드가 나에게 전화를 허용하지 않습니다 그러나 나는 아래있는 UIImage
let logoView: UIImageView = {
let LV = UIImageView()
let thumbnail = resizeImage(image: "DN", CGSize.init(width:70, height:70))
LV.image = thumbnail
LV.contentMode = .scaleAspectFill
LV.layer.masksToBounds = true
return LV
}()
같은 확장을 호출하여 이미지 크기를 조정하려고
extension UIImage {
func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage {
let size = image.size
let widthRatio = targetSize.width/image.size.width
let heightRatio = targetSize.height/image.size.height
// Figure out what our orientation is, and use that to form the rectangle
var newSize: CGSize
if(widthRatio > heightRatio) {
newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
} else {
newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
}
// This is the rect that we've calculated out and this is what is actually used below
let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
// Actually do the resizing to the rect using the ImageContext stuff
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
image.draw(in: rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
}
이있는 UIImage 크기 조정 확장자가 크기 조정 함수 확장. 이미지의 크기를 올바르게 조정하려면 어떻게해야합니까?
func setupViews() {
addSubview(logoView)
}
http://stackoverflow.com/questions/31314412/how-to-
이 함수는 다음과 같이해야한다, 해결하려면 크기 조정 - 이미지 - 신속한 –