YBImageBrowser Documentation

repository·master·Indexed 25 days ago

https://github.com/indulgein/ybimagebrowser

An iOS image browser supporting images and videos. It integrates with SDWebImage for asynchronous downloading and caching, and YYImage for high-performance display and encoding of animated formats like WebP, APNG, and GIF. Key features include support for local and network images, video playback via YBIBVideoData, customizable icons and copywriting, and flexible installation options via CocoaPods, Carthage, or manual integration.

Tokens
3.6K
Snippets
12
Records
28
Agent score
82%

What's inside YBImageBrowser

  1. Overview of SDWebImage features

    master

    SDWebImage is an asynchronous image downloader with built-in cache support. It provides categories for common UI elements like UIImageView, UIButton, and MKAnnotationView to simplify web image loading and cache management.

    Key features include:

    • Asynchronous memory and disk caching with automatic expiration.
    • Background image decompression to prevent main thread blocking.
    • Support for animated images (GIF, etc.).
    • Customizable and composable transformations applied post-download.
    • Loading indicators.
    • Guarantees against redundant downloads for the same URL and retrying bogus URLs.
  2. Supported image formats in SDWebImage

    master

    SDWebImage supports standard formats via UIImage (JPEG, PNG, etc.) and can be extended for others using coder plugins:

    • Standard: JPEG, PNG, and GIF.
    • WebP: Supported via the SDWebImageWebPCoder module (includes animated WebP).
    • Extensible: Supports APNG, BPG, HFIF, SVG, etc., through additional coder plugins.
  3. Install SDWebImage via Swift Package Manager

    master

    SDWebImage supports Swift Package Manager (SwiftPM) from version 5.1.0.

    For Xcode users:

    1. Go to File -> Swift Packages -> Add Package Dependency.
    2. Enter the repository URL: https://github.com/SDWebImage/SDWebImage.git.
    3. Select your dependency type (tagged version, branch, or commit).

    For framework authors (Package.swift): Add the dependency to your Package.swift file:

    let package = Package(
        // 5.1.0 ..< 6.0.0
        dependencies: [
            .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0")
        ],
        // ...
    )
    let package = Package(
        // 5.1.0 ..< 6.0.0
        dependencies: [
            .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0")
        ],
        // ...
    )
  4. Install YYImage manually

    master

    To install YYImage manually:

    1. Download all files in the YYImage subdirectory.
    2. Add the source files to your Xcode project.
    3. Link the following required frameworks:
      • UIKit
      • CoreFoundation
      • QuartzCore
      • AssetsLibrary
      • ImageIO
      • Accelerate
      • MobileCoreServices
      • libz
    4. Import YYImage.h.

    Note on WebP support: If you need WebP support, add Vendor/WebP.framework (static library) to your Xcode project.

  5. Install YBImageBrowser manually

    master

    To install manually:

    1. Download the YBImageBrowser folder and drag it into your project. If you need video support, also download and include the Video folder.
    2. Link the following frameworks: SDWebImage and YYImage.
    3. Import the headers:
      • Core: YBImageBrowser.h
      • Video: YBIBVideoData.h
    4. For WebP support, ensure you have the WebP support files from the YYImage repository.
  6. Install YYImage via Carthage

    master

    To install YYImage using Carthage:

    1. Add github "ibireme/YYImage" to your Cartfile.
    2. Run carthage update --platform ios.
    3. Add the generated framework to your Xcode project.
    4. Import <YYImage/YYImage.h>.

    Note on WebP support: The Carthage framework does not include the WebP component. To support WebP, use CocoaPods or install the WebP component manually.

  7. Install SDWebImage via CocoaPods

    master

    Add SDWebImage to your Podfile to manage it via CocoaPods. You can install the default Core module or specific subspecs like MapKit.

    To use SDWebImage as a static framework (recommended for Swift projects to avoid use_frameworks!), use modular headers:

    platform :ios, '8.0'
    # Use modular headers for static framework support
    use_modular_headers!
    pod 'SDWebImage', :modular_headers => true

    To use it as a dynamic framework, use use_frameworks!:

    platform :ios, '8.0'
    use_frameworks!
    pod 'SDWebImage'

    To install specific subspecs (e.g., MapKit):

    pod 'SDWebImage/MapKit'
    platform :ios, '8.0'
    # Uncomment the next line when you want all Pods as static framework
    # use_modular_headers!
    pod 'SDWebImage', :modular_headers => true
  8. Install YYImage via CocoaPods

    master

    To install YYImage using CocoaPods:

    1. Update CocoaPods to the latest version.
    2. Add pod 'YYImage' to your Podfile.
    3. Run pod install or pod update.
    4. Import <YYImage/YYImage.h> in your source files.

    Note on WebP support: The default pod does not include WebP support. To enable it, add pod 'YYImage/WebP' to your Podfile instead.

  9. Install YBImageBrowser via CocoaPods

    master

    You can install YBImageBrowser using CocoaPods. The library supports modular imports: the core image browsing functionality is the base, while video playback is an optional extension.

    Standard Installation

    1. Add the following to your Podfile:
    pod 'YBImageBrowser'
    pod 'YBImageBrowser/Video'  # Add this if you need video support
    1. Run pod install or pod update.
    2. Import the headers:
      • Core: #import <YBImageBrowser/YBImageBrowser.h>
      • Video: #import <YBImageBrowser/YBIBVideoData.h>

    WebP Support

    To support WebP images, add pod 'YYImage/WebP' to your Podfile.

    Removing SDWebImage Dependency

    If you want to avoid a dependency on SDWebImage (requires version >= 3.0.4), use the NOSD subspecs:

    pod 'YBImageBrowser/NOSD'
    pod 'YBImageBrowser/VideoNOSD' # If video is needed

    Note: When using NOSD, you MUST define a class that implements the YBIBWebImageMediator protocol and assign it to the webImageMediator property of the YBImageBrowser instance. You can refer to YBIBDefaultWebImageMediator for a reference implementation.

    pod 'YBImageBrowser'
    pod 'YBImageBrowser/Video'
  10. Install SDWebImage via Carthage

    master

    Add the following entry to your Cartfile to use Carthage as your dependency manager:

    gitub "SDWebImage/SDWebImage"

    Then run carthage update.

    Note: Carthage builds all components (including SDWebImageMapKit). If you do not need MapKit, you can manually delete the SDWebImageMapKit framework from the Carthage Build directory after the update completes.

    github "SDWebImage/SDWebImage"
  11. Optimize memory usage for low-end devices

    master

    If you encounter Out-Of-Memory (OOM) issues on low-end devices, you can manually reduce the memory footprint by adjusting the following properties:

    For individual images (YBIBImageData):

    • shouldPreDecodeAsync = NO: Disables asynchronous pre-decoding.
    • cuttingZoomScale = 10: Increases the threshold for triggering high-definition cropping (drawing smaller areas reduces pressure).

    For the browser (YBImageBrowser):

    • ybib_imageCache.imageCacheCountLimit = 1: Reduces the number of cached images.
    • preloadCount = 0: Disables preloading of upcoming images.
    YBIBImageData *data = YBIBImageData.new;
    // Disable pre-decoding
    data.shouldPreDecodeAsync = NO;
    // Increase cutting zoom scale
    data.cuttingZoomScale = 10;
    
    YBImageBrowser *browser = YBImageBrowser.new;
    // Lower the image cache limit
    browser.ybib_imageCache.imageCacheCountLimit = 1;
    // Set preload count to 0
    browser.preloadCount = 0;
  12. Troubleshoot WebP and APNG issues

    master

    WebP not displaying

    • Ensure WebP.framework is added to your project.
    • Verify installation by calling YYImageWebPAvailable().

    APNG not playing

    • Disable Compress PNG Files and Remove Text Metadata From PNG Files in your Xcode Build Settings.
    • Alternatively, rename the file extension to .apng.