Latest 1.0.2
License MIT
Platforms ios 5.0, requires ARC


What does it do?

LDOAlignedImageView is a lightweight subclass of UIImageView that aligns image edges to view edges in UIViewContentModeAspectFill mode (not in AspectFit mode, though).

This is useful, for example, if you want to have a photo fill an area on the screen, but you do not want to clip off the head of a person or a logo that is placed near the top of the image. Simply set alignTop to YES.

Its interface is compatible with UIImageViewAligned (four properties alignTop, alignBottom, alignLeft, alignRight), and can be configured in Interface Builder thanks to IBInspectable.

How is it implemented? How does it differ from UIImageViewAligned?

Just like UIImageViewAligned, this is a UIImageView subclass so that existing categories work. Apart from setting the Custom Class, no changes to XIBs and storyboards are required.

Unlike UIImageViewAligned, LDOAlignedImageView does not use nested views at all. This prevents issues where UIImageView keeps resetting the image property on the outer UIImageView, showing two images instead of one.

Instead, LDOAlignedImageView sets the layer.contentsRect property to a rectangle that is larger than 1.0 x 1.0. This lets us influence how UIImageView (actually CALayer) centres the image.


LDOAlignedImageView should work on all versions of iOS.


You can simply copy the two files in Classes into your project, but the easiest way is to use CocoaPods.

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like LDOAlignedImageView in your projects.


platform :ios, "7.0"

pod "LDOAlignedImageView", :git => ""


LDOAlignedImageView is released under the MIT License.

Latest podspec

    "name": "JLNRGravityImageView",
    "version": "1.0.2",
    "summary": "UIImageView subclass that pins image edges to view edges in AspectFill mode",
    "description": "                   This lightweight UIImageView subclass controls how images are clipped in AspectFill content mode.n                   n                   By default, UIImageView centres the image, but JLNRGravityImageView can define the u2018gravityu2019 so that only one side of the image is trimmed off.n                   n                   This is useful, for example, if you want to avoid clipping off the top of a photo because faces are more interesting than shoes.n                   n                   For the curious, this is implemented by adjusting the CALayeru2019s contentsRect property.n",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Julian Raschke": "[email protected]"
    "platforms": {
        "ios": "5.0"
    "source": {
        "git": "",
        "tag": "v1.0.2"
    "source_files": [
    "requires_arc": true

Pin It on Pinterest

Share This