UIImageExt
public extension UIImage {
//Image resize width
//ex -> image.widthScaledImage(maximumWidth:300)
func widthScaledImage(maximumWidth: CGFloat) -> UIImage {
let scale = maximumWidth / self.size.width
let newHeight = self.size.height * scale
UIGraphicsBeginImageContext(CGSize(width:maximumWidth, height:newHeight))
self.draw(in: CGRect(x: 0, y: 0, width:maximumWidth, height:newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
//Image Nine patch center
//ex -> image.imageCenterNinePath(centerPixel:2)
func imageCenterNinePath(centerPixel:CGFloat) -> UIImage {
let w = (self.size.width - centerPixel)/2
let h = (self.size.height - centerPixel)/2
return self.resizableImage(withCapInsets: UIEdgeInsetsMake(h, w, h, w))
}
}
'iOS' 카테고리의 다른 글
[swift] 정규식 (0) | 2017.12.01 |
---|---|
[swift] Util(UIImageView) (0) | 2017.12.01 |
[swift] Util(String) (0) | 2017.12.01 |
[swift] iOS 주소 찾기 (0) | 2017.11.15 |
앱스토어 버전 가져오기 (0) | 2015.09.11 |