Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sochalewski/uiimageviewalignedswift
A UIImageView subclass which allows you to align the image left/right/top/bottom, even when contentMode is AspectFit. Swift now.
https://github.com/sochalewski/uiimageviewalignedswift
Last synced: 2 days ago
JSON representation
A UIImageView subclass which allows you to align the image left/right/top/bottom, even when contentMode is AspectFit. Swift now.
- Host: GitHub
- URL: https://github.com/sochalewski/uiimageviewalignedswift
- Owner: sochalewski
- License: mit
- Created: 2016-02-08T08:42:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-04-10T21:08:39.000Z (over 2 years ago)
- Last Synced: 2024-11-05T19:59:35.983Z (9 days ago)
- Language: Swift
- Homepage:
- Size: 74.2 KB
- Stars: 236
- Watchers: 4
- Forks: 67
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UIImageViewAlignedSwift
[![Version](https://img.shields.io/cocoapods/v/UIImageViewAlignedSwift.svg?style=flat)](http://cocoapods.org/pods/UIImageViewAlignedSwift)
[![License](https://img.shields.io/cocoapods/l/UIImageViewAlignedSwift.svg?style=flat)](http://cocoapods.org/pods/UIImageViewAlignedSwift)
[![Platform](https://img.shields.io/cocoapods/p/UIImageViewAlignedSwift.svg?style=flat)](http://cocoapods.org/pods/UIImageViewAlignedSwift)
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift_Package_Manager-compatible-4BC51D.svg)](https://www.swift.org/package-manager/)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/Carthage/Carthage)## Usage
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
* iOS 8.0+, tvOS 9.0+
* Swift 5.x## Installation
### Package Manager
You can add UIImageViewAlignedSwift to an Xcode project by adding it as a package dependency.
1. From the **File** menu, select **Add Packages…**
2. Enter `https://github.com/sochalewski/UIImageViewAlignedSwift` into the package repository URL text field.
3. Add the package to your app target.### CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
```bash
$ gem install cocoapods
```To integrate UIImageViewAlignedSwift into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
pod 'UIImageViewAlignedSwift'
```Then, run the following command:
```bash
$ pod install
```### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
```bash
$ brew update
$ brew install carthage
```To integrate UIImageViewAlignedSwift into your Xcode project using Carthage, specify it in your `Cartfile`:
```ogdl
github "sochalewski/UIImageViewAlignedSwift"
```Run `carthage update` to build the framework and drag the built `UIImageViewAlignedSwift.framework` into your Xcode project.
## What is it?
It is a subclass of `UIImageView` that allows you to customize the alignment of the displayed image inside the view's frame.
This works even if the `contentMode` is set to `.scaleAspectFit`, `.scaleAspectFill` or `.scaleToFill`.It is rewritten to Swift based on original [UIImageViewAligned by reydanro](https://github.com/reydanro/UIImageViewAligned).
## Why a subclass of UIImageView, and not a standard UIView?
Because there are many cool categories built on top of `UIImageView`. Subclassing a standard `UIView` would mean losing them.
For example, `AFNetworking`'s async `UIImageView` category works perfectly using this container class, and you don't have to worry about a thing.
## How does it work?
When initialized, `UIImageViewAligned` will create a inner `UIImageView` which will actually hold the image displayed.
The main class then just repositions this inner `UIImageView` to achieve your desired alignment.At runtime, you can change the `image`, `contentMode` or `alignment` and the image will reposition itself correctly.
The `image` property of `UIImageViewAligned` is overwritten to forward the calls to the inner `UIImageView`, so you can just drag and drop into your app.
## Author
Piotr Sochalewski, sochalewski.github.io
## License
UIImageViewAlignedSwift is available under the MIT license. See the LICENSE file for more info.