示例
NFImageView
- 实时加载进度。
- 带有进度条或旋转器的加载选项。
- 使用缩略图和较大图像进行模糊的加载选项。
- 在表格或收集视图中防止加载错误图像。
- 使用 CoreGraphics 在上下文中绘制图像。
- 支持 '内容填充位置' : '.Top, .Left, .Right, .Bottom'
要求
- iOS 13.0+
- Xcode 11+
- Swift 5.1+
安装
CocoaPods
NFImageView 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
platform :ios, '13.0'
use_frameworks! # remove this if this will be used in ObjC code.
pod "NFImageView"
Carthage
创建一个 Cartfile
文件,列出框架并运行 carthage update
命令。按照 说明 将 $(SRCROOT)/Carthage/Build/iOS/NFImageView.framework
添加到 iOS 项目中。
github "nferocious76/NFImageView"
手动
- 下载并将
/Pod/Classes
文件夹拖放到您的项目中。 - 恭喜!
视图功能
可用功能
imageView.setImage(fromURL: <#T##URL#>)
imageView.setImage(fromURL: <#T##URL#>, completion: <#T##NFImageViewRequestCompletion?##NFImageViewRequestCompletion?##(NFImageViewRequestCode, NSError?) -> Void#>)
imageView.setImage(fromURLString: <#T##String#>)
imageView.setImage(fromURLString: <#T##String#>, completion: <#T##NFImageViewRequestCompletion?##NFImageViewRequestCompletion?##(NFImageViewRequestCode, NSError?) -> Void#>)
imageView.setThumbImageAndLargeImage(fromURL: <#T##URL#>, largeURL: <#T##URL#>)
imageView.setThumbImageAndLargeImage(fromURL: <#T##URL#>, largeURL: <#T##URL#>, completion: <#T##NFImageViewRequestCompletion?##NFImageViewRequestCompletion?##(NFImageViewRequestCode, NSError?) -> Void#>)
imageView.setThumbImageAndLargeImage(fromURLString: <#T##String#>, largeURLString: <#T##String#>)
imageView.setThumbImageAndLargeImage(fromURLString: <#T##String#>, largeURLString: <#T##String#>, completion: <#T##NFImageViewRequestCompletion?##NFImageViewRequestCompletion?##(NFImageViewRequestCode, NSError?) -> Void#>)
使用示例
可选配置
// set capacity
NFImageCacheAPI.shared.setCapacity(memoryCapacity: 200 * 1024 * 1024, preferredMemoryUsageAfterPurge: 80 * 1024 * 1024)
// it is nescessary to configure `imageCache` with `setCapacity(memoryCapacity: UInt64, preferredMemoryUsageAfterPurge: UInt64)`
// before creating new downloader configuration and not vice versa or else it will not be registered to the downloader
// and it will use the default
NFImageCacheAPI.shared.createDownloader(downloadPrioritization: .fifo, maximumActiveDownloads: 10)
// link of images
let thumbnail = "https://scontent.fmnl4-4.fna.fbcdn.net/v/t1.0-9/13529069_10202382982213334_6754953260473113193_n.jpg?oh=28c0f3e751a9177e5ca0afaf23be919e&oe=57F9EEF9"
let largeImage = "https://scontent.fmnl4-4.fna.fbcdn.net/t31.0-8/13584845_10202382982333337_2990050100601729771_o.jpg"
// NFImageView is like a regular UIImageView, you can either subclass a UIImageView in the IB, just set the module to `NFUIKitUtilities` for the IB to read the class.
// create an imageview
let imageview = NFImageView(frame: CGRectMake(0, 0, 100, 100))
// `loadingEnabled` flag is use to force disable any loading that should occur. This will make it load like normal. default to `true`
// imageView.loadingEnabled = false // set this to disable loading.
// set loading type
imageview.loadingType = .Spinner
// loading an image without blur effect.
imageView.setImageFromURLString(largeImage)
// loading an image with blur effect using thumbnail and large image.
imageview.setThumbImageAndLargeImageFromURLString(thumbURLString: thumbnail, largeURLString: largeImage)
// Set image aspect
imageView.contentViewMode = .Fill || .AspectFit || .AspectFill || .OriginalSize
// Set image fill location
imageView.contentViewFill = .Center || .Top || .Left || .Right || .Bottom
解决 IBDesignable 导致的渲染和更新自动布局状态问题,导致 Storyboard 无法使用的工作方法。
将以下脚本添加到您的 Podfile
: 资源来源: https://github.com/CocoaPods/CocoaPods/issues/5334
# Workaround for @IBDesignable
post_install do |installer|
installer.pods_project.targets.each do |target|
next if target.product_type == "com.apple.product-type.bundle"
target.build_configurations.each do |config|
config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR'
end
end
end
贡献
我们非常希望您为 NFImageView
贡献。有关更多详细信息,请参阅 LICENSE 文件。
作者
Neil Francis Ramirez Hipona, [email protected]
许可
NFImageView 使用 MIT 许可。有关更多详细信息,请参阅 LICENSE 文件。