IOS-2064 - scale image IOS-2064
authorMartin Brude
Wed, 05 Feb 2020 12:24:35 +0100
branchIOS-2064
changeset 116692384524ed8f1
parent 11667 0eb248dd2759
child 11680 dbbd8efe030d
IOS-2064 - scale image
pEpForiOS/Util/Appearance.swift
subModules/pEpIOSToolbox/pEpIOSToolbox/UIKit/UIImage+GIF.swift
     1.1 --- a/pEpForiOS/Util/Appearance.swift	Wed Feb 05 11:38:43 2020 +0100
     1.2 +++ b/pEpForiOS/Util/Appearance.swift	Wed Feb 05 12:24:35 2020 +0100
     1.3 @@ -72,7 +72,7 @@
     1.4          
     1.5          let titleTextAttributes: [NSAttributedString.Key : Any] = [.foregroundColor: color,
     1.6                                                                     .font: font,
     1.7 -                                                                   .baselineOffset: -2
     1.8 +                                                                   .baselineOffset: 2
     1.9          ]
    1.10          appearance.buttonAppearance.normal.titleTextAttributes = titleTextAttributes
    1.11          appearance.backButtonAppearance.normal.titleTextAttributes = titleTextAttributes
    1.12 @@ -80,7 +80,10 @@
    1.13          appearance.largeTitleTextAttributes = titleTextAttributes
    1.14          appearance.doneButtonAppearance.normal.titleTextAttributes = titleTextAttributes
    1.15  
    1.16 -        let chevronLeftImg = UIImage(named: "chevron-icon-left")
    1.17 +        
    1.18 +        
    1.19 +        let chevronLeftImg = UIImage(named: "chevron-icon-left")?
    1.20 +            .resizeImage(targetSize: CGSize(width: 15, height: 25))
    1.21          appearance.setBackIndicatorImage(chevronLeftImg, transitionMaskImage: chevronLeftImg)
    1.22  
    1.23          return appearance
     2.1 --- a/subModules/pEpIOSToolbox/pEpIOSToolbox/UIKit/UIImage+GIF.swift	Wed Feb 05 11:38:43 2020 +0100
     2.2 +++ b/subModules/pEpIOSToolbox/pEpIOSToolbox/UIKit/UIImage+GIF.swift	Wed Feb 05 12:24:35 2020 +0100
     2.3 @@ -66,4 +66,35 @@
     2.4              return nil
     2.5          }
     2.6      }
     2.7 +    
     2.8 +    
     2.9 +
    2.10 +    public func resizeImage(targetSize: CGSize) -> UIImage? {
    2.11 +
    2.12 +        let widthRatio  = targetSize.width  / size.width
    2.13 +        let heightRatio = targetSize.height / size.height
    2.14 +
    2.15 +        // Figure out what our orientation is, and use that to form the rectangle
    2.16 +        var newSize: CGSize
    2.17 +        if(widthRatio > heightRatio) {
    2.18 +            newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
    2.19 +        } else {
    2.20 +            newSize = CGSize(width: size.width * widthRatio,  height: size.height * widthRatio)
    2.21 +        }
    2.22 +
    2.23 +        // This is the rect that we've calculated out and this is what is actually used below
    2.24 +        let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
    2.25 +
    2.26 +        // Actually do the resizing to the rect using the ImageContext stuff
    2.27 +        UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
    2.28 +        draw(in: rect)
    2.29 +        let newImage = UIGraphicsGetImageFromCurrentImageContext()
    2.30 +        UIGraphicsEndImageContext()
    2.31 +
    2.32 +        return newImage
    2.33 +    }
    2.34 +
    2.35 +
    2.36  }
    2.37 +
    2.38 +