UIImagePlusPDF 1.2.0

UIImagePlusPDF 1.2.0

Dima Mishchenko 维护。



  • 编者
  • Dima Mishchenko

UIImagePlusPDF

Swift 4.2 CocoaPods compatible Packagist

这是一个为使用 PDF 文件扩展了 UIImage 的库。使用 UIImagePlusPDF,您可以避免很多 png 图像文件(1x、2x、3x 尺寸)并简单地用单个 pdf 文件替换它们。

安装

CocoaPods:

pod 'UIImagePlusPDF'
import UIImagePlusPDF

使用方法

简单示例

let imageView = UIImageView()
let image = UIImage.pdfImage(with: "imageName")
imageView.image = image

其他选项

//with custom width 
UIImage.pdfImage(with: "imageName", width: 350)

//with custom height
UIImage.pdfImage(with: "imageName", height: 350)

//with custom size
UIImage.pdfImage(with: "imageName", size: CGSize(width: 300, height:  400))

//with page number
UIImage.pdfImage(with: "multipage pdf file", width: 300, pageNumber: 2)

//same options with resource url
UIImage.pdfImage(with: URL(string: "path"))

缓存

内存缓存

//using NSCache
//default is true
UIImage.pdfCacheInMemory = true

磁盘缓存

//default is false
UIImage.pdfCacheOnDisk = true

缓存删除

//all cache
UIImage.removeAllPDFCache()

//all memory cache
UIImage.removeAllPDFMemoryCache()

//all disk cache
UIImage.removeAllPDFDiskCache()

//memory cached pdf with name
UIImage.removeMemoryCachedPDFImage(
    with: "pdf name", 
    size: imageSize, 
    pageNumber: 1 /*optional, default is 1*/
)

//memory cached pdf with url
UIImage.removeMemoryCachedPDFImage(
    with: URL(string: "path"), 
    size: imageSize, 
    pageNumber: 1 /*optional, default is 1*/
)

//disk cached pdf with name
UIImage.removeDiskCachedPDFImage(
    with: "pdf name", 
    size: imageSize, 
    pageNumber: 1 /*optional, default is 1*/
)

//disk cached pdf with url
UIImage.removeDiskCachedPDFImage(
    with: URL(string: "path"), 
    size: imageSize, 
    pageNumber: 1 /*optional, default is 1*/
)

许可

UIImagePlusPDF 基于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。