Giter Club home page Giter Club logo

thtiledimageview's Introduction

THTiledImageView

Version License: MIT Build Status Platform Swift 4.0

Feature

  • ๐Ÿ–ผ THTiledImageView fully support UIScrollView. You can subclass it and use it.
  • ๐Ÿ”ช Support Image Cutting Extension Method to generate tiled images.
  • ๐Ÿ” You can set different tiled images based on user's zoom scale.

Demo

THTileImageView

Installation

CocoaPods

To integrate THTiledImageView into your Xcode project using CocoaPods, specify it in your Podfile:

pod "THTiledImageView"

Requirements

THTiledImageView is written in Swift 4, and compatible with iOS 9.0+

How to use

SubClassing

  1. THTiledImageScrollView is subclass of UIScrollVIew. Create THTiledImageScrollView from Storyboard or programmatically.

  2. Create dataSource class that is subclass of THTiledImageViewDataSource.

var dataSource: THTiledImageViewDataSource?
  1. Here is THTiledImageViewDataSource options that you can use.
func setupExample(imageSize: CGSize, tileSize: [CGSize], imageURL: URL) {

    dataSource = MyTileImageViewDataSource(imageSize: imageSize, tileSize: tileSize, imageURL: imageURL)
    dataSource?.thumbnailImageName = "bench"

    // maximun tile level
    // When you zoom in this level, you can see level 5 tiles.
    dataSource?.maxTileLevel = 5

    // minimum tile level
    dataSource?.minTileLevel = 1

    // scrollView allowable maximum zoom level
    dataSource?.maxZoomLevel = 8

    dataSource?.imageExtension = "jpg"
    tileImageScrollView.set(dataSource: dataSource!)

    dataSource?.requestBackgroundImage { _ in
        // do something after image shows.
    }
}

Zoom and Tile Level

THTiledImageView's zoom level and tile level can be set separately.

Zoom Level

UIScrollView's Zoom level. Default minimum zoom level is scale aspect fit size of scrollView. maximum zoom level is allowable zoom in level.

Tile Level

Tiled images can be shown at specific zoom level based on tile level. For example, if you set (minTileLevel, maxTileLevel) = (1, 5), You can set 5 different images by tile level.

Tile level 1 can be used wide range of image.

Tile level 5(or more than 1) can be used narrow range of image.

Cutting Image

โ—๏ธ So far cutting and rendering images cannot be done simultaneously. You should cut image first, and relaunch the app.

We offer you image cutting function(UIImage.saveTileOf(size:name:withExtension:). Specify the size of tiles by levels.

// size and level will be 512-1, 256-2, 128-3(size-level).
let tiles: [CGSize] = [CGSize(width: 512, height: 512),
                       CGSize(width: 256, height: 256), CGSize(width: 128, height: 128)]

// static function
UIImage.saveTileOf(size: tiles, name: "bench", withExtension: "jpg")

Tiled Images path

Tiled images will be saved on your cache directory. Path of the cache directory:

let cachesPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] as String

If imagefile saved successfully, you can see images from cache directory. Here is the rule of directory path and image file name rules.

Path Rules ./imageName/imageSize/{imageName_imageSize_level_x_y}.jpg
Example    ./bench/256/bench_256_1_0_0.jpg

โ—๏ธ If you create images on your own, you need to obey the path rules.

THTiledImageScrollViewDelegate

You can use UIScrollViewDelegate methods from THTiledImageScrollViewDelegate.

public protocol THTiledImageScrollViewDelegate: class {
    func didScroll(scrollView: THTiledImageScrollView)
    func didZoom(scrollView: THTiledImageScrollView)
}

See our example for more details.

License

THTiledImageView is released under the MIT license. See LICENSE for details.

thtiledimageview's People

Contributors

hcn1519 avatar

Watchers

Carabineiro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.