Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples to README #31

Merged
merged 6 commits into from
Oct 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,47 @@

<img src="https://raw.githubusercontent.com/hyperoslo/Imaginary/master/Images/icon.png" alt="Brick Icon" align="right" />

## Description

Using remote images in an application is more or less a requirement these days.
This process should be easy, straight-forward and hassle free, and with `Imaginary`, it is.
With a narrow yet flexible public API, you can set images using URL's, add
placeholders, pre-process images and use callbacks for when images are set.

## Usage

### Set image with URL
```swift
let imageView: UIImageView()
let imageURL: NSURL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will go with URL 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comment.

imageView.setImage(URL: imageURL)
```

### How to apply placeholder images
```swift
let imageView: UIImageView()
let placeholder = UIImage(named: "PlaceholderImage")
let imageURL: NSURL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean imageURL = URL(string: ...) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the 2.2 version.

imageView.setImage(URL: imageURL, placeholder: placeholder)
```

### Pre-processing images
```swift
let imageView: UIImageView()
let imageURL: NSURL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")
imageView.setImage(URL: imageURL, preprocess: { image in
/// Apply pre-process here ...
return image
})
```

### Callback when image is set to the image view
```swift
<API>
let imageView: UIImageView()
let imageURL: NSURL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")
imageView.setImage(URL: imageURL) { image in
/// This closure gets called when the image is set to the image view.
}
```

## Installation
Expand Down