GithubHelp home page GithubHelp logo

sochalewski / uiimageviewalignedswift Goto Github PK

View Code? Open in Web Editor NEW
236.0 4.0 66.0 76 KB

A UIImageView subclass which allows you to align the image left/right/top/bottom, even when contentMode is AspectFit. Swift now.

License: MIT License

Ruby 9.21% Swift 87.26% Objective-C 3.53%

uiimageviewalignedswift's Introduction

UIImageViewAlignedSwift

Version License Platform Swift Package Manager compatible Carthage compatible

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 is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

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

pod 'UIImageViewAlignedSwift'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate UIImageViewAlignedSwift into your Xcode project using Carthage, specify it in your Cartfile:

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.

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.

uiimageviewalignedswift's People

Contributors

basantashraf avatar benjamindetroch avatar joeboyscout04 avatar mickmaccallum avatar rcaroff-molotov avatar romanpodymov avatar shanev avatar sochalewski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

uiimageviewalignedswift's Issues

ImageAlign not working

I've added custom class to UIImageViewAligned and set contentMode to aspectFit, alignBottom = On but it still center like below.
image

Dismissing ViewControllers above causes UI bug

EDIT

It was not setting the image programmatically that causes the issue, but dismissing a UIViewController above the one with the image after presenting it as a popover i.e..
Below the original post.


I have set UIImageViewAligned as my UIImageView's class in storyboard, enabled right alignment and provided an image:

screen shot 2017-10-30 at 14 18 32

It works just like it should until I update the image programmatically like:

imageView.image = UIImage(named: "account.png")!

This results in the following UI:

screen shot 2017-10-30 at 14 19 30

Any idea why this happens & what I can do about it?

Pod -> 0.1 installs 0.3.1

i added in my pod file the following:

pod 'UIImageViewAlignedSwift', '~> 0.1'

but pod install installs version 0.3.1 which causes build failures as this version requires the newer swift versions.
Can you please check this?
Thank you very much

Image duplication in iOS 13b3 [BUG]

I have the same problem!
If the image is aligned, 2 images appear, one aligned and the second in the center of the original. Please pack it as soon as possible!

Swift 3

Time to merge the Swift 3 branch! Is it ready?

Property alignTop

Hi, I'm a little new on the subject of iOS and not quite understand some things. It happens the following:

  1. You install the UIImageViewAlignedSwift library in my xcode project with Pods.
  2. I Add a imageView my storyboard.
  3. Change the class of the image view to UIImageViewAligned
  4. Add the property alignTop boolean true.

The problem is that when I run the app the compiler tells me that there is no such property. can someone please help me?

Tag Carthage Updates

Would it be possible for you to do a release with the new Carthage support? I'd love to tag against that release instead of master for our release.

Image duplication in iOS 13b1

Hi,

First off thanks much for this library!

iOS13b1 is causing a duplication of the image when using a UIImageViewAligned. If you align the image you'll see the image aligned the way you want, but you'll also see the same image in the center of the view. (both in simulator and device)

If you use UIImageViewAligned and don't align it you'll see a duplication of the image right under the UIImageView it creates.

I've attached a screenshot from Reveal below. Just a simple project with one image.

The bottom layer is referenced as UIImageViewAlignedSwift.UIImageViewAligned, and the top is the UIImageView the library creates.

Screen Shot 2019-06-06 at 8 09 55 AM

Thanks again!

required code signature missing

I use pod install
I got Error when I set ViewControll Class on Storyboard

IB Designables: Failed to render and update auto layout status for XXXXXXXX  (iGI-eV-pSd): dlopen(UIImageViewAlignedSwift.framework, 1): no suitable image found.  Did find:
	UIImageViewAlignedSwift.framework: required code signature missing for 'UIImageViewAlignedSwift.framework'

Any example?

Hi , I am new to swift.
I looking for the image can align top when the image view is set to Aspect Fill in storyboard inside the tableview.

so how i call the align top function for this pod?

Seems not to work?

I've tried to integrate your UIImageViewAlignedSwift class as follows, but unfortunately the UIImage itself is not rendered at all (see attached screenshot). What's wrong?

let imageView = UIImageViewAligned(image: UIImage(named:"my-image"))
imageView.contentMode = .scaleAspectFit
imageView.scaling = .down
imageView.alignment = .bottomRight
imageView.backgroundColor = .red

imageView.translatesAutoresizingMaskIntoConstraints = false

self.view.addSubview(self.rightImageView)

let imageViews = ["imageView":imageView]

self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[imageView(32)]-6-|", options: [], metrics: nil, views: imageViews))
self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[imageView(32)]-6-|", options: [], metrics: nil, views: imageViews))

And here is the result (the red box in the bottom right corner):

simulator screen shot 21 02 2017 20 10 27

storyboard problem

when I try to add user defined attribute I get this error:

Failed to set (alignBottom) user defined inspected property on (UIImageViewAlignedSwift.UIImageViewAligned): [<UIImageViewAlignedSwift.UIImageViewAligned 0x7fe046480f00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key alignBottom.

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.