閱讀395 返回首頁    go 汽車大全


一個從UIImageView中獲得Image位置的函數


 (CGRect)getFrameSizeForImage:(UIImage *)image inImageView:(UIImageView *)imageView {
    
    float hfactor = image.size.width / imageView.frame.size.width;
    float vfactor = image.size.height / imageView.frame.size.height;
    
    float factor = fmax(hfactor, vfactor);
    
    // Divide the size by the greater of the vertical or horizontal shrinkage factor
    float newWidth = image.size.width / factor;
    float newHeight = image.size.height / factor;
    
    // Then figure out if you need to offset it to center vertically or horizontally
    float leftOffset = (imageView.frame.size.width - newWidth) / 2;
    float topOffset = (imageView.frame.size.height - newHeight) / 2;
    
    return CGRectMake(leftOffset, topOffset, newWidth, newHeight);
}

廢話不多說貼代碼。再stackOverflow中找到的馬克下!

最後更新:2017-04-04 07:03:44

  上一篇:go Oracle無法啟動2——監聽程序當前無法識別連接描述符中請求的服務
  下一篇:go Oracle無法啟動2——監聽程序當前無法識別連接描述符中請求的服務