Skip to content

NFImageView acts like a normal UIImageView with the added feature of location fill: '.Top, .Left, .Right, .Bottom'

License

Notifications You must be signed in to change notification settings

nfhipona/NFImageView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo

NFImageView

  • Realtime loading progress.
  • Loading option with progress or spinner.
  • Loading option with blur using thumbnail and a larger image.
  • Prevent loading wrong image when on a table or collection view.
  • Uses CoreGraphics to draw image in context.
  • Supports 'Content Fill Location' : '.Top, .Left, .Right, .Bottom'

Requirements

  • iOS 13.0+
  • Xcode 11+
  • Swift 5.1+

Installation

CocoaPods

NFImageView is available through CocoaPods. To install it, simply add the following line to your Podfile:

platform :ios, '13.0'
use_frameworks! # remove this if this will be used in ObjC code.

pod "NFImageView"

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/NFImageView.framework to an iOS project.

github "nferocious76/NFImageView"

Manually

  1. Download and drop /Pod/Classes folder in your project.
  2. Congratulations!

Image View Functions

Available functions

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#>)

Usage example

Optional Configuration

// 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

Workaround for IBDesignable causing issues for render and update auto layout status causing the storyboard to be unusable.

Add this script to your Podfile: Source: 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

Contribute

We would love for you to contribute to NFImageView. See the LICENSE file for more info.

Author

Neil Francis Ramirez Hipona, nferocious76@gmail.com

License

NFImageView is available under the MIT license. See the LICENSE file for more info.

About

NFImageView acts like a normal UIImageView with the added feature of location fill: '.Top, .Left, .Right, .Bottom'

Resources

License

Stars

Watchers

Forks

Packages

No packages published