├── .gitignore ├── Example ├── ImageAlignment.xcodeproj │ └── project.pbxproj ├── ImageAlignment │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ └── Main.storyboard │ ├── ImageAlignment-Info.plist │ ├── ImageAlignment-Prefix.pch │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── LaunchImage.launchimage │ │ │ └── Contents.json │ ├── ViewController.h │ ├── ViewController.m │ ├── en.lproj │ │ └── InfoPlist.strings │ ├── main.m │ ├── melinda_landscape.jpg │ └── melinda_portrait.jpg └── ImageAlignmentTests │ ├── ImageAlignmentTests-Info.plist │ ├── ImageAlignmentTests.m │ └── en.lproj │ └── InfoPlist.strings ├── LICENSE ├── Package.swift ├── README.md ├── UIImageViewAligned.podspec ├── UIImageViewAligned ├── UIImageViewAligned.h └── UIImageViewAligned.m └── docs └── IBsetup.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /Example/ImageAlignment.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C027041017A6FAEC0039CEC1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C027040F17A6FAEC0039CEC1 /* Foundation.framework */; }; 11 | C027041217A6FAEC0039CEC1 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C027041117A6FAEC0039CEC1 /* CoreGraphics.framework */; }; 12 | C027041417A6FAEC0039CEC1 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C027041317A6FAEC0039CEC1 /* UIKit.framework */; }; 13 | C027041A17A6FAEC0039CEC1 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C027041817A6FAEC0039CEC1 /* InfoPlist.strings */; }; 14 | C027041C17A6FAEC0039CEC1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C027041B17A6FAEC0039CEC1 /* main.m */; }; 15 | C027042017A6FAEC0039CEC1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C027041F17A6FAEC0039CEC1 /* AppDelegate.m */; }; 16 | C027042317A6FAEC0039CEC1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C027042117A6FAEC0039CEC1 /* Main.storyboard */; }; 17 | C027042617A6FAEC0039CEC1 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C027042517A6FAEC0039CEC1 /* ViewController.m */; }; 18 | C027042817A6FAEC0039CEC1 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C027042717A6FAEC0039CEC1 /* Images.xcassets */; }; 19 | C027042F17A6FAEC0039CEC1 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C027042E17A6FAEC0039CEC1 /* XCTest.framework */; }; 20 | C027043017A6FAEC0039CEC1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C027040F17A6FAEC0039CEC1 /* Foundation.framework */; }; 21 | C027043117A6FAEC0039CEC1 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C027041317A6FAEC0039CEC1 /* UIKit.framework */; }; 22 | C027043917A6FAEC0039CEC1 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C027043717A6FAEC0039CEC1 /* InfoPlist.strings */; }; 23 | C027043B17A6FAEC0039CEC1 /* ImageAlignmentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C027043A17A6FAEC0039CEC1 /* ImageAlignmentTests.m */; }; 24 | C027044717A6FB170039CEC1 /* UIImageViewAligned.m in Sources */ = {isa = PBXBuildFile; fileRef = C027044617A6FB170039CEC1 /* UIImageViewAligned.m */; }; 25 | C027044917A6FE200039CEC1 /* melinda_landscape.jpg in Resources */ = {isa = PBXBuildFile; fileRef = C027044817A6FE200039CEC1 /* melinda_landscape.jpg */; }; 26 | C027044B17A6FE780039CEC1 /* melinda_portrait.jpg in Resources */ = {isa = PBXBuildFile; fileRef = C027044A17A6FE780039CEC1 /* melinda_portrait.jpg */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXContainerItemProxy section */ 30 | C027043217A6FAEC0039CEC1 /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = C027040417A6FAEC0039CEC1 /* Project object */; 33 | proxyType = 1; 34 | remoteGlobalIDString = C027040B17A6FAEC0039CEC1; 35 | remoteInfo = ImageAlignment; 36 | }; 37 | /* End PBXContainerItemProxy section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | C027040C17A6FAEC0039CEC1 /* ImageAlignment.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ImageAlignment.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | C027040F17A6FAEC0039CEC1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 42 | C027041117A6FAEC0039CEC1 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 43 | C027041317A6FAEC0039CEC1 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 44 | C027041717A6FAEC0039CEC1 /* ImageAlignment-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ImageAlignment-Info.plist"; sourceTree = ""; }; 45 | C027041917A6FAEC0039CEC1 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 46 | C027041B17A6FAEC0039CEC1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 47 | C027041D17A6FAEC0039CEC1 /* ImageAlignment-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ImageAlignment-Prefix.pch"; sourceTree = ""; }; 48 | C027041E17A6FAEC0039CEC1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 49 | C027041F17A6FAEC0039CEC1 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 50 | C027042217A6FAEC0039CEC1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 51 | C027042417A6FAEC0039CEC1 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 52 | C027042517A6FAEC0039CEC1 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 53 | C027042717A6FAEC0039CEC1 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 54 | C027042D17A6FAEC0039CEC1 /* ImageAlignmentTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ImageAlignmentTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | C027042E17A6FAEC0039CEC1 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 56 | C027043617A6FAEC0039CEC1 /* ImageAlignmentTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ImageAlignmentTests-Info.plist"; sourceTree = ""; }; 57 | C027043817A6FAEC0039CEC1 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 58 | C027043A17A6FAEC0039CEC1 /* ImageAlignmentTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ImageAlignmentTests.m; sourceTree = ""; }; 59 | C027044517A6FB170039CEC1 /* UIImageViewAligned.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIImageViewAligned.h; sourceTree = ""; }; 60 | C027044617A6FB170039CEC1 /* UIImageViewAligned.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIImageViewAligned.m; sourceTree = ""; }; 61 | C027044817A6FE200039CEC1 /* melinda_landscape.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = melinda_landscape.jpg; sourceTree = ""; }; 62 | C027044A17A6FE780039CEC1 /* melinda_portrait.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = melinda_portrait.jpg; sourceTree = ""; }; 63 | /* End PBXFileReference section */ 64 | 65 | /* Begin PBXFrameworksBuildPhase section */ 66 | C027040917A6FAEC0039CEC1 /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | C027041217A6FAEC0039CEC1 /* CoreGraphics.framework in Frameworks */, 71 | C027041417A6FAEC0039CEC1 /* UIKit.framework in Frameworks */, 72 | C027041017A6FAEC0039CEC1 /* Foundation.framework in Frameworks */, 73 | ); 74 | runOnlyForDeploymentPostprocessing = 0; 75 | }; 76 | C027042A17A6FAEC0039CEC1 /* Frameworks */ = { 77 | isa = PBXFrameworksBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | C027042F17A6FAEC0039CEC1 /* XCTest.framework in Frameworks */, 81 | C027043117A6FAEC0039CEC1 /* UIKit.framework in Frameworks */, 82 | C027043017A6FAEC0039CEC1 /* Foundation.framework in Frameworks */, 83 | ); 84 | runOnlyForDeploymentPostprocessing = 0; 85 | }; 86 | /* End PBXFrameworksBuildPhase section */ 87 | 88 | /* Begin PBXGroup section */ 89 | C027040317A6FAEC0039CEC1 = { 90 | isa = PBXGroup; 91 | children = ( 92 | C027041517A6FAEC0039CEC1 /* ImageAlignment */, 93 | C027043417A6FAEC0039CEC1 /* ImageAlignmentTests */, 94 | C027040E17A6FAEC0039CEC1 /* Frameworks */, 95 | C027040D17A6FAEC0039CEC1 /* Products */, 96 | ); 97 | sourceTree = ""; 98 | }; 99 | C027040D17A6FAEC0039CEC1 /* Products */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | C027040C17A6FAEC0039CEC1 /* ImageAlignment.app */, 103 | C027042D17A6FAEC0039CEC1 /* ImageAlignmentTests.xctest */, 104 | ); 105 | name = Products; 106 | sourceTree = ""; 107 | }; 108 | C027040E17A6FAEC0039CEC1 /* Frameworks */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | C027040F17A6FAEC0039CEC1 /* Foundation.framework */, 112 | C027041117A6FAEC0039CEC1 /* CoreGraphics.framework */, 113 | C027041317A6FAEC0039CEC1 /* UIKit.framework */, 114 | C027042E17A6FAEC0039CEC1 /* XCTest.framework */, 115 | ); 116 | name = Frameworks; 117 | sourceTree = ""; 118 | }; 119 | C027041517A6FAEC0039CEC1 /* ImageAlignment */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | C027044417A6FAFD0039CEC1 /* UIImageViewAligned */, 123 | C027041E17A6FAEC0039CEC1 /* AppDelegate.h */, 124 | C027041F17A6FAEC0039CEC1 /* AppDelegate.m */, 125 | C027042117A6FAEC0039CEC1 /* Main.storyboard */, 126 | C027042417A6FAEC0039CEC1 /* ViewController.h */, 127 | C027042517A6FAEC0039CEC1 /* ViewController.m */, 128 | C027042717A6FAEC0039CEC1 /* Images.xcassets */, 129 | C027044817A6FE200039CEC1 /* melinda_landscape.jpg */, 130 | C027044A17A6FE780039CEC1 /* melinda_portrait.jpg */, 131 | C027041617A6FAEC0039CEC1 /* Supporting Files */, 132 | ); 133 | path = ImageAlignment; 134 | sourceTree = ""; 135 | }; 136 | C027041617A6FAEC0039CEC1 /* Supporting Files */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | C027041717A6FAEC0039CEC1 /* ImageAlignment-Info.plist */, 140 | C027041817A6FAEC0039CEC1 /* InfoPlist.strings */, 141 | C027041B17A6FAEC0039CEC1 /* main.m */, 142 | C027041D17A6FAEC0039CEC1 /* ImageAlignment-Prefix.pch */, 143 | ); 144 | name = "Supporting Files"; 145 | sourceTree = ""; 146 | }; 147 | C027043417A6FAEC0039CEC1 /* ImageAlignmentTests */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | C027043A17A6FAEC0039CEC1 /* ImageAlignmentTests.m */, 151 | C027043517A6FAEC0039CEC1 /* Supporting Files */, 152 | ); 153 | path = ImageAlignmentTests; 154 | sourceTree = ""; 155 | }; 156 | C027043517A6FAEC0039CEC1 /* Supporting Files */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | C027043617A6FAEC0039CEC1 /* ImageAlignmentTests-Info.plist */, 160 | C027043717A6FAEC0039CEC1 /* InfoPlist.strings */, 161 | ); 162 | name = "Supporting Files"; 163 | sourceTree = ""; 164 | }; 165 | C027044417A6FAFD0039CEC1 /* UIImageViewAligned */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | C027044517A6FB170039CEC1 /* UIImageViewAligned.h */, 169 | C027044617A6FB170039CEC1 /* UIImageViewAligned.m */, 170 | ); 171 | name = UIImageViewAligned; 172 | path = ../../UIImageViewAligned; 173 | sourceTree = ""; 174 | }; 175 | /* End PBXGroup section */ 176 | 177 | /* Begin PBXNativeTarget section */ 178 | C027040B17A6FAEC0039CEC1 /* ImageAlignment */ = { 179 | isa = PBXNativeTarget; 180 | buildConfigurationList = C027043E17A6FAEC0039CEC1 /* Build configuration list for PBXNativeTarget "ImageAlignment" */; 181 | buildPhases = ( 182 | C027040817A6FAEC0039CEC1 /* Sources */, 183 | C027040917A6FAEC0039CEC1 /* Frameworks */, 184 | C027040A17A6FAEC0039CEC1 /* Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | ); 190 | name = ImageAlignment; 191 | productName = ImageAlignment; 192 | productReference = C027040C17A6FAEC0039CEC1 /* ImageAlignment.app */; 193 | productType = "com.apple.product-type.application"; 194 | }; 195 | C027042C17A6FAEC0039CEC1 /* ImageAlignmentTests */ = { 196 | isa = PBXNativeTarget; 197 | buildConfigurationList = C027044117A6FAEC0039CEC1 /* Build configuration list for PBXNativeTarget "ImageAlignmentTests" */; 198 | buildPhases = ( 199 | C027042917A6FAEC0039CEC1 /* Sources */, 200 | C027042A17A6FAEC0039CEC1 /* Frameworks */, 201 | C027042B17A6FAEC0039CEC1 /* Resources */, 202 | ); 203 | buildRules = ( 204 | ); 205 | dependencies = ( 206 | C027043317A6FAEC0039CEC1 /* PBXTargetDependency */, 207 | ); 208 | name = ImageAlignmentTests; 209 | productName = ImageAlignmentTests; 210 | productReference = C027042D17A6FAEC0039CEC1 /* ImageAlignmentTests.xctest */; 211 | productType = "com.apple.product-type.bundle.unit-test"; 212 | }; 213 | /* End PBXNativeTarget section */ 214 | 215 | /* Begin PBXProject section */ 216 | C027040417A6FAEC0039CEC1 /* Project object */ = { 217 | isa = PBXProject; 218 | attributes = { 219 | LastUpgradeCheck = 0500; 220 | ORGANIZATIONNAME = "Andrei Stanescu"; 221 | TargetAttributes = { 222 | C027042C17A6FAEC0039CEC1 = { 223 | TestTargetID = C027040B17A6FAEC0039CEC1; 224 | }; 225 | }; 226 | }; 227 | buildConfigurationList = C027040717A6FAEC0039CEC1 /* Build configuration list for PBXProject "ImageAlignment" */; 228 | compatibilityVersion = "Xcode 3.2"; 229 | developmentRegion = English; 230 | hasScannedForEncodings = 0; 231 | knownRegions = ( 232 | en, 233 | Base, 234 | ); 235 | mainGroup = C027040317A6FAEC0039CEC1; 236 | productRefGroup = C027040D17A6FAEC0039CEC1 /* Products */; 237 | projectDirPath = ""; 238 | projectRoot = ""; 239 | targets = ( 240 | C027040B17A6FAEC0039CEC1 /* ImageAlignment */, 241 | C027042C17A6FAEC0039CEC1 /* ImageAlignmentTests */, 242 | ); 243 | }; 244 | /* End PBXProject section */ 245 | 246 | /* Begin PBXResourcesBuildPhase section */ 247 | C027040A17A6FAEC0039CEC1 /* Resources */ = { 248 | isa = PBXResourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | C027044917A6FE200039CEC1 /* melinda_landscape.jpg in Resources */, 252 | C027044B17A6FE780039CEC1 /* melinda_portrait.jpg in Resources */, 253 | C027042817A6FAEC0039CEC1 /* Images.xcassets in Resources */, 254 | C027041A17A6FAEC0039CEC1 /* InfoPlist.strings in Resources */, 255 | C027042317A6FAEC0039CEC1 /* Main.storyboard in Resources */, 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | }; 259 | C027042B17A6FAEC0039CEC1 /* Resources */ = { 260 | isa = PBXResourcesBuildPhase; 261 | buildActionMask = 2147483647; 262 | files = ( 263 | C027043917A6FAEC0039CEC1 /* InfoPlist.strings in Resources */, 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | /* End PBXResourcesBuildPhase section */ 268 | 269 | /* Begin PBXSourcesBuildPhase section */ 270 | C027040817A6FAEC0039CEC1 /* Sources */ = { 271 | isa = PBXSourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | C027042617A6FAEC0039CEC1 /* ViewController.m in Sources */, 275 | C027042017A6FAEC0039CEC1 /* AppDelegate.m in Sources */, 276 | C027041C17A6FAEC0039CEC1 /* main.m in Sources */, 277 | C027044717A6FB170039CEC1 /* UIImageViewAligned.m in Sources */, 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | C027042917A6FAEC0039CEC1 /* Sources */ = { 282 | isa = PBXSourcesBuildPhase; 283 | buildActionMask = 2147483647; 284 | files = ( 285 | C027043B17A6FAEC0039CEC1 /* ImageAlignmentTests.m in Sources */, 286 | ); 287 | runOnlyForDeploymentPostprocessing = 0; 288 | }; 289 | /* End PBXSourcesBuildPhase section */ 290 | 291 | /* Begin PBXTargetDependency section */ 292 | C027043317A6FAEC0039CEC1 /* PBXTargetDependency */ = { 293 | isa = PBXTargetDependency; 294 | target = C027040B17A6FAEC0039CEC1 /* ImageAlignment */; 295 | targetProxy = C027043217A6FAEC0039CEC1 /* PBXContainerItemProxy */; 296 | }; 297 | /* End PBXTargetDependency section */ 298 | 299 | /* Begin PBXVariantGroup section */ 300 | C027041817A6FAEC0039CEC1 /* InfoPlist.strings */ = { 301 | isa = PBXVariantGroup; 302 | children = ( 303 | C027041917A6FAEC0039CEC1 /* en */, 304 | ); 305 | name = InfoPlist.strings; 306 | sourceTree = ""; 307 | }; 308 | C027042117A6FAEC0039CEC1 /* Main.storyboard */ = { 309 | isa = PBXVariantGroup; 310 | children = ( 311 | C027042217A6FAEC0039CEC1 /* Base */, 312 | ); 313 | name = Main.storyboard; 314 | sourceTree = ""; 315 | }; 316 | C027043717A6FAEC0039CEC1 /* InfoPlist.strings */ = { 317 | isa = PBXVariantGroup; 318 | children = ( 319 | C027043817A6FAEC0039CEC1 /* en */, 320 | ); 321 | name = InfoPlist.strings; 322 | sourceTree = ""; 323 | }; 324 | /* End PBXVariantGroup section */ 325 | 326 | /* Begin XCBuildConfiguration section */ 327 | C027043C17A6FAEC0039CEC1 /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ALWAYS_SEARCH_USER_PATHS = NO; 331 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 332 | CLANG_CXX_LIBRARY = "libc++"; 333 | CLANG_ENABLE_MODULES = YES; 334 | CLANG_ENABLE_OBJC_ARC = YES; 335 | CLANG_WARN_BOOL_CONVERSION = YES; 336 | CLANG_WARN_CONSTANT_CONVERSION = YES; 337 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 338 | CLANG_WARN_EMPTY_BODY = YES; 339 | CLANG_WARN_ENUM_CONVERSION = YES; 340 | CLANG_WARN_INT_CONVERSION = YES; 341 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 342 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 343 | CODE_SIGN_IDENTITY = "iPhone Developer: AG AG (4AJVDG7NFQ)"; 344 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: AG AG (4AJVDG7NFQ)"; 345 | COPY_PHASE_STRIP = NO; 346 | GCC_C_LANGUAGE_STANDARD = gnu99; 347 | GCC_DYNAMIC_NO_PIC = NO; 348 | GCC_OPTIMIZATION_LEVEL = 0; 349 | GCC_PREPROCESSOR_DEFINITIONS = ( 350 | "DEBUG=1", 351 | "$(inherited)", 352 | ); 353 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 354 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 355 | GCC_WARN_UNDECLARED_SELECTOR = YES; 356 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 357 | GCC_WARN_UNUSED_FUNCTION = YES; 358 | GCC_WARN_UNUSED_VARIABLE = YES; 359 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 360 | ONLY_ACTIVE_ARCH = YES; 361 | SDKROOT = iphoneos; 362 | }; 363 | name = Debug; 364 | }; 365 | C027043D17A6FAEC0039CEC1 /* Release */ = { 366 | isa = XCBuildConfiguration; 367 | buildSettings = { 368 | ALWAYS_SEARCH_USER_PATHS = NO; 369 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 370 | CLANG_CXX_LIBRARY = "libc++"; 371 | CLANG_ENABLE_MODULES = YES; 372 | CLANG_ENABLE_OBJC_ARC = YES; 373 | CLANG_WARN_BOOL_CONVERSION = YES; 374 | CLANG_WARN_CONSTANT_CONVERSION = YES; 375 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 376 | CLANG_WARN_EMPTY_BODY = YES; 377 | CLANG_WARN_ENUM_CONVERSION = YES; 378 | CLANG_WARN_INT_CONVERSION = YES; 379 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 380 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 381 | CODE_SIGN_IDENTITY = "iPhone Developer: AG AG (4AJVDG7NFQ)"; 382 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: AG AG (4AJVDG7NFQ)"; 383 | COPY_PHASE_STRIP = YES; 384 | ENABLE_NS_ASSERTIONS = NO; 385 | GCC_C_LANGUAGE_STANDARD = gnu99; 386 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 387 | GCC_WARN_UNDECLARED_SELECTOR = YES; 388 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 389 | GCC_WARN_UNUSED_FUNCTION = YES; 390 | GCC_WARN_UNUSED_VARIABLE = YES; 391 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 392 | SDKROOT = iphoneos; 393 | VALIDATE_PRODUCT = YES; 394 | }; 395 | name = Release; 396 | }; 397 | C027043F17A6FAEC0039CEC1 /* Debug */ = { 398 | isa = XCBuildConfiguration; 399 | buildSettings = { 400 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 401 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 402 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 403 | GCC_PREFIX_HEADER = "ImageAlignment/ImageAlignment-Prefix.pch"; 404 | INFOPLIST_FILE = "ImageAlignment/ImageAlignment-Info.plist"; 405 | PRODUCT_NAME = "$(TARGET_NAME)"; 406 | WRAPPER_EXTENSION = app; 407 | }; 408 | name = Debug; 409 | }; 410 | C027044017A6FAEC0039CEC1 /* Release */ = { 411 | isa = XCBuildConfiguration; 412 | buildSettings = { 413 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 414 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 415 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 416 | GCC_PREFIX_HEADER = "ImageAlignment/ImageAlignment-Prefix.pch"; 417 | INFOPLIST_FILE = "ImageAlignment/ImageAlignment-Info.plist"; 418 | PRODUCT_NAME = "$(TARGET_NAME)"; 419 | WRAPPER_EXTENSION = app; 420 | }; 421 | name = Release; 422 | }; 423 | C027044217A6FAEC0039CEC1 /* Debug */ = { 424 | isa = XCBuildConfiguration; 425 | buildSettings = { 426 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ImageAlignment.app/ImageAlignment"; 427 | FRAMEWORK_SEARCH_PATHS = ( 428 | "$(SDKROOT)/Developer/Library/Frameworks", 429 | "$(inherited)", 430 | "$(SYSTEM_APPS_DIR)/Xcode5-DP3.app/Contents/Developer/Library/Frameworks", 431 | ); 432 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 433 | GCC_PREFIX_HEADER = "ImageAlignment/ImageAlignment-Prefix.pch"; 434 | GCC_PREPROCESSOR_DEFINITIONS = ( 435 | "DEBUG=1", 436 | "$(inherited)", 437 | ); 438 | INFOPLIST_FILE = "ImageAlignmentTests/ImageAlignmentTests-Info.plist"; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | TEST_HOST = "$(BUNDLE_LOADER)"; 441 | WRAPPER_EXTENSION = xctest; 442 | }; 443 | name = Debug; 444 | }; 445 | C027044317A6FAEC0039CEC1 /* Release */ = { 446 | isa = XCBuildConfiguration; 447 | buildSettings = { 448 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ImageAlignment.app/ImageAlignment"; 449 | FRAMEWORK_SEARCH_PATHS = ( 450 | "$(SDKROOT)/Developer/Library/Frameworks", 451 | "$(inherited)", 452 | "$(SYSTEM_APPS_DIR)/Xcode5-DP3.app/Contents/Developer/Library/Frameworks", 453 | ); 454 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 455 | GCC_PREFIX_HEADER = "ImageAlignment/ImageAlignment-Prefix.pch"; 456 | INFOPLIST_FILE = "ImageAlignmentTests/ImageAlignmentTests-Info.plist"; 457 | PRODUCT_NAME = "$(TARGET_NAME)"; 458 | TEST_HOST = "$(BUNDLE_LOADER)"; 459 | WRAPPER_EXTENSION = xctest; 460 | }; 461 | name = Release; 462 | }; 463 | /* End XCBuildConfiguration section */ 464 | 465 | /* Begin XCConfigurationList section */ 466 | C027040717A6FAEC0039CEC1 /* Build configuration list for PBXProject "ImageAlignment" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | C027043C17A6FAEC0039CEC1 /* Debug */, 470 | C027043D17A6FAEC0039CEC1 /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | defaultConfigurationName = Release; 474 | }; 475 | C027043E17A6FAEC0039CEC1 /* Build configuration list for PBXNativeTarget "ImageAlignment" */ = { 476 | isa = XCConfigurationList; 477 | buildConfigurations = ( 478 | C027043F17A6FAEC0039CEC1 /* Debug */, 479 | C027044017A6FAEC0039CEC1 /* Release */, 480 | ); 481 | defaultConfigurationIsVisible = 0; 482 | defaultConfigurationName = Release; 483 | }; 484 | C027044117A6FAEC0039CEC1 /* Build configuration list for PBXNativeTarget "ImageAlignmentTests" */ = { 485 | isa = XCConfigurationList; 486 | buildConfigurations = ( 487 | C027044217A6FAEC0039CEC1 /* Debug */, 488 | C027044317A6FAEC0039CEC1 /* Release */, 489 | ); 490 | defaultConfigurationIsVisible = 0; 491 | defaultConfigurationName = Release; 492 | }; 493 | /* End XCConfigurationList section */ 494 | }; 495 | rootObject = C027040417A6FAEC0039CEC1 /* Project object */; 496 | } 497 | -------------------------------------------------------------------------------- /Example/ImageAlignment/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ImageAlignment 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import 9 | 10 | @interface AppDelegate : UIResponder 11 | 12 | @property (strong, nonatomic) UIWindow *window; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Example/ImageAlignment/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ImageAlignment 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import "AppDelegate.h" 9 | 10 | @implementation AppDelegate 11 | 12 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 13 | { 14 | // Override point for customization after application launch. 15 | return YES; 16 | } 17 | 18 | - (void)applicationWillResignActive:(UIApplication *)application 19 | { 20 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 21 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 22 | } 23 | 24 | - (void)applicationDidEnterBackground:(UIApplication *)application 25 | { 26 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 27 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 28 | } 29 | 30 | - (void)applicationWillEnterForeground:(UIApplication *)application 31 | { 32 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 33 | } 34 | 35 | - (void)applicationDidBecomeActive:(UIApplication *)application 36 | { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | - (void)applicationWillTerminate:(UIApplication *)application 41 | { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Example/ImageAlignment/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 67 | 73 | 79 | 85 | 91 | 106 | 112 | 118 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /Example/ImageAlignment/ImageAlignment-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.reydanro.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Example/ImageAlignment/ImageAlignment-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Example/ImageAlignment/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "60x60", 11 | "scale" : "2x" 12 | } 13 | ], 14 | "info" : { 15 | "version" : 1, 16 | "author" : "xcode" 17 | } 18 | } -------------------------------------------------------------------------------- /Example/ImageAlignment/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Example/ImageAlignment/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ImageAlignment 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import 9 | #import "UIImageViewAligned.h" 10 | 11 | @interface ViewController : UIViewController { 12 | NSArray* _contentModeStrings; 13 | } 14 | @property (weak, nonatomic) IBOutlet UIImageViewAligned *alignedImageView; 15 | 16 | @property (weak, nonatomic) IBOutlet UISwitch *swLandscape; 17 | @property (weak, nonatomic) IBOutlet UIButton *btnContentMode; 18 | @property (weak, nonatomic) IBOutlet UISwitch *swAlignTop; 19 | @property (weak, nonatomic) IBOutlet UISwitch *swAlignRight; 20 | @property (weak, nonatomic) IBOutlet UISwitch *swAlignBottom; 21 | @property (weak, nonatomic) IBOutlet UISwitch *swAlignLeft; 22 | 23 | - (IBAction)onSwitchLandscape:(id)sender; 24 | - (IBAction)onButtonContentMode:(id)sender; 25 | - (IBAction)onSwitchAlignTop:(id)sender; 26 | - (IBAction)onSwitchAlignRight:(id)sender; 27 | - (IBAction)onSwitchAlignBottom:(id)sender; 28 | - (IBAction)onSwitchAlignLeft:(id)sender; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Example/ImageAlignment/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ImageAlignment 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import "ViewController.h" 9 | 10 | @interface ViewController () 11 | 12 | @end 13 | 14 | @implementation ViewController 15 | 16 | - (void)viewDidLoad 17 | { 18 | [super viewDidLoad]; 19 | 20 | _contentModeStrings = [NSArray arrayWithObjects: 21 | @"UIViewContentModeScaleToFill", 22 | @"UIViewContentModeScaleAspectFit", // contents scaled to fit with fixed aspect. remainder is transparent 23 | @"UIViewContentModeScaleAspectFill", // contents scaled to fill with fixed aspect. some portion of content may be clipped. 24 | @"UIViewContentModeRedraw", // redraw on bounds change (calls -setNeedsDisplay) 25 | @"UIViewContentModeCenter", // contents remain same size. positioned adjusted. 26 | @"UIViewContentModeTop", 27 | @"UIViewContentModeBottom", 28 | @"UIViewContentModeLeft", 29 | @"UIViewContentModeRight", 30 | @"UIViewContentModeTopLeft", 31 | @"UIViewContentModeTopRight", 32 | @"UIViewContentModeBottomLeft", 33 | @"UIViewContentModeBottomRight", nil]; 34 | 35 | _swLandscape.on = (_alignedImageView.image != nil) && _alignedImageView.image.size.width >= _alignedImageView.image.size.height; 36 | 37 | _swAlignLeft.on = _alignedImageView.alignLeft; 38 | _swAlignRight.on = _alignedImageView.alignRight; 39 | _swAlignTop.on = _alignedImageView.alignTop; 40 | _swAlignBottom.on = _alignedImageView.alignBottom; 41 | 42 | [self refreshContentModeButtonTitle]; 43 | } 44 | 45 | - (IBAction)onSwitchLandscape:(id)sender { 46 | if (_swLandscape.on) 47 | _alignedImageView.image = [UIImage imageNamed:@"melinda_landscape.jpg"]; 48 | else 49 | _alignedImageView.image = [UIImage imageNamed:@"melinda_portrait.jpg"]; 50 | } 51 | 52 | - (IBAction)onButtonContentMode:(id)sender 53 | { 54 | _alignedImageView.contentMode = (_alignedImageView.contentMode + 1) % (UIViewContentModeBottomRight+1); // bit of hardcoding..but only for the purposes of this example 55 | [self refreshContentModeButtonTitle]; 56 | } 57 | 58 | - (IBAction)onSwitchAlignTop:(id)sender { 59 | _alignedImageView.alignTop 60 | = _swAlignTop.on; 61 | } 62 | 63 | - (IBAction)onSwitchAlignRight:(id)sender { 64 | _alignedImageView.alignRight = _swAlignRight.on; 65 | } 66 | 67 | - (IBAction)onSwitchAlignBottom:(id)sender { 68 | _alignedImageView.alignBottom = _swAlignBottom.on; 69 | } 70 | 71 | - (IBAction)onSwitchAlignLeft:(id)sender { 72 | _alignedImageView.alignLeft = _swAlignLeft.on; 73 | } 74 | 75 | - (void)refreshContentModeButtonTitle 76 | { 77 | [_btnContentMode setTitle:_contentModeStrings[_alignedImageView.contentMode] forState:UIControlStateNormal]; 78 | } 79 | @end 80 | -------------------------------------------------------------------------------- /Example/ImageAlignment/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Example/ImageAlignment/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ImageAlignment 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) 13 | { 14 | @autoreleasepool { 15 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Example/ImageAlignment/melinda_landscape.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reydanro/UIImageViewAligned/9f6bc486026064242133c21715220bbc34bffa51/Example/ImageAlignment/melinda_landscape.jpg -------------------------------------------------------------------------------- /Example/ImageAlignment/melinda_portrait.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reydanro/UIImageViewAligned/9f6bc486026064242133c21715220bbc34bffa51/Example/ImageAlignment/melinda_portrait.jpg -------------------------------------------------------------------------------- /Example/ImageAlignmentTests/ImageAlignmentTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.reydanro.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Example/ImageAlignmentTests/ImageAlignmentTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImageAlignmentTests.m 3 | // ImageAlignmentTests 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import 9 | 10 | @interface ImageAlignmentTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation ImageAlignmentTests 15 | 16 | - (void)setUp 17 | { 18 | [super setUp]; 19 | 20 | // Set-up code here. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Tear-down code here. 26 | 27 | [super tearDown]; 28 | } 29 | 30 | - (void)testExample 31 | { 32 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Example/ImageAlignmentTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Andrei Stanescu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.4 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "UIImageViewAligned", 8 | products: [ 9 | // Products define the executables and libraries a package produces, and make them visible to other packages. 10 | .library( 11 | name: "UIImageViewAligned", 12 | targets: ["UIImageViewAligned"]), 13 | ], 14 | dependencies: [ 15 | // Dependencies declare other packages that this package depends on. 16 | // .package(url: /* package url */, from: "1.0.0"), 17 | ], 18 | targets: [ 19 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 20 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 21 | .target( 22 | name: "UIImageViewAligned", 23 | dependencies: [], 24 | path: "UIImageViewAligned", 25 | publicHeadersPath: "." 26 | ) 27 | ] 28 | ) 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | What is it? 2 | =========== 3 | 4 | It is a subclass of `UIImageView` that allows you to customize the alignment of the displayed image inside the view's frame. 5 | This works even if the `contentMode` is set to `AspectFit`, `AspectFill` or `ScaleToFill`. 6 | 7 | 8 | Why a subclass of UIImageView, and not a standard UIView? 9 | ========================================================= 10 | Because there are many cool categories built on top of UIImageView. Subclassing a standard UIView would mean losing them. 11 | 12 | For example, AFNetworking's async `UIImageView` category works perfectly using this container class, and you don't have to worry about a thing. 13 | 14 | 15 | How does it work? 16 | ================= 17 | When initialized, `UIImageViewAligned` will create a inner `UIImageView` which will actually hold the image displayed. 18 | The main class then just repositions this inner `UIImageView` to achieve your desired alignment. 19 | 20 | At runtime, you can change the image, contentMode or alignment and the image will reposition itself correctly. 21 | 22 | The `image` property of UIImageViewAligned is overwritten to forward the calls to the inner `UIImageView`, so you can just drag-n-drop into your app. 23 | 24 | Compatibility 25 | ============= 26 | From what I tested, it works on iOS 6.0+. 27 | Also, it supports autorotation and will reposition the image correctly. 28 | 29 | Using Interface Builder 30 | ======================= 31 | You can setup the alignment from Interface Builder using the `Identity Inspector` tab for the UIImageViewAligned. 32 | There, you can add custom boolean properties that will be set when the view is instantiated. 33 | The possible boolean names are: 34 | `alignLeft` 35 | `alignRight` 36 | `alignTop` 37 | `alignBottom` 38 | 39 | Below is a screenshot of an example. You will not get an immediate feedback in IB regarding your alignment, but it will work at runtime. 40 | 41 | ![alt tag](https://raw.github.com/reydanro/UIImageViewAligned/master/docs/IBsetup.png) 42 | -------------------------------------------------------------------------------- /UIImageViewAligned.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "UIImageViewAligned" 4 | s.version = "0.0.1" 5 | s.summary = "A UIImageView subclass which allows you to align the image left/right/top/bottom, even when contentMode is AspectFit." 6 | 7 | s.description = "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 AspectFit, AspectFill or ScaleToFill." 8 | 9 | s.homepage = "https://github.com/reydanro/UIImageViewAligned" 10 | s.license = { :type => "MIT", :file => "LICENSE" } 11 | 12 | s.author = "Andrei Stanescu" 13 | s.social_media_url = "http://www.mindtreatstudios.com/" 14 | s.platform = :ios 15 | 16 | s.source = { :git => "https://github.com/reydanro/UIImageViewAligned.git", :tag => "pod-0.0.1" } 17 | s.source_files = "UIImageViewAligned" 18 | 19 | s.framework = "UIKit" 20 | 21 | end 22 | -------------------------------------------------------------------------------- /UIImageViewAligned/UIImageViewAligned.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageViewAligned.h 3 | // awards 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import 9 | 10 | typedef enum 11 | { 12 | UIImageViewAlignmentMaskCenter = 0, 13 | 14 | UIImageViewAlignmentMaskLeft = 1, 15 | UIImageViewAlignmentMaskRight = 2, 16 | UIImageViewAlignmentMaskTop = 4, 17 | UIImageViewAlignmentMaskBottom = 8, 18 | 19 | UIImageViewAlignmentMaskBottomLeft = UIImageViewAlignmentMaskBottom | UIImageViewAlignmentMaskLeft, 20 | UIImageViewAlignmentMaskBottomRight = UIImageViewAlignmentMaskBottom | UIImageViewAlignmentMaskRight, 21 | UIImageViewAlignmentMaskTopLeft = UIImageViewAlignmentMaskTop | UIImageViewAlignmentMaskLeft, 22 | UIImageViewAlignmentMaskTopRight = UIImageViewAlignmentMaskTop | UIImageViewAlignmentMaskRight, 23 | 24 | }UIImageViewAlignmentMask; 25 | 26 | typedef UIImageViewAlignmentMask UIImageViewAignmentMask __attribute__((deprecated("Use UIImageViewAlignmentMask. Use of UIImageViewAignmentMask (misspelled) is deprecated."))); 27 | 28 | 29 | 30 | @interface UIImageViewAligned : UIImageView 31 | 32 | // This property holds the current alignment 33 | @property (nonatomic) UIImageViewAlignmentMask alignment; 34 | 35 | // Properties needed for Interface Builder quick setup 36 | @property (nonatomic) BOOL alignLeft; 37 | @property (nonatomic) BOOL alignRight; 38 | @property (nonatomic) BOOL alignTop; 39 | @property (nonatomic) BOOL alignBottom; 40 | 41 | // Make the UIImageView scale only up or down 42 | // This are used only if the content mode is Scaled 43 | @property (nonatomic) BOOL enableScaleUp; 44 | @property (nonatomic) BOOL enableScaleDown; 45 | 46 | // Just in case you need access to the inner image view 47 | @property (nonatomic, readonly) UIImageView* realImageView; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /UIImageViewAligned/UIImageViewAligned.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageViewAligned.m 3 | // awards 4 | // 5 | // Created by Andrei Stanescu on 7/29/13. 6 | // 7 | 8 | #import "UIImageViewAligned.h" 9 | 10 | @implementation UIImageViewAligned 11 | 12 | - (id)initWithFrame:(CGRect)frame 13 | { 14 | self = [super initWithFrame:frame]; 15 | if (self) 16 | { 17 | [self commonInit]; 18 | } 19 | return self; 20 | } 21 | 22 | 23 | - (id)initWithImage:(UIImage *)image 24 | { 25 | self = [super initWithImage:image]; 26 | if (self) 27 | { 28 | [self commonInit]; 29 | } 30 | return self; 31 | } 32 | 33 | - (id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage 34 | { 35 | self = [super initWithImage:image highlightedImage:highlightedImage]; 36 | if (self) 37 | [self commonInit]; 38 | 39 | return self; 40 | } 41 | 42 | - (id)initWithCoder:(NSCoder *)aDecoder 43 | { 44 | self = [super initWithCoder:aDecoder]; 45 | if (self) 46 | [self commonInit]; 47 | return self; 48 | } 49 | 50 | - (void)commonInit 51 | { 52 | _enableScaleDown = TRUE; 53 | _enableScaleUp = TRUE; 54 | 55 | _alignment = UIImageViewAlignmentMaskCenter; 56 | 57 | _realImageView = [[UIImageView alloc] initWithFrame:self.bounds]; 58 | _realImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 59 | _realImageView.contentMode = self.contentMode; 60 | [self addSubview:_realImageView]; 61 | 62 | // Move any image we might have from this container to the real image view 63 | if (super.image != nil) 64 | { 65 | UIImage* img = super.image; 66 | super.image = nil; 67 | self.image = img; 68 | } 69 | } 70 | 71 | - (UIImage*)image 72 | { 73 | return _realImageView.image; 74 | } 75 | 76 | - (void)setImage:(UIImage *)image 77 | { 78 | [_realImageView setImage:image]; 79 | [self setNeedsLayout]; 80 | } 81 | 82 | - (void)setContentMode:(UIViewContentMode)contentMode 83 | { 84 | [super setContentMode:contentMode]; 85 | _realImageView.contentMode = contentMode; 86 | [self setNeedsLayout]; 87 | } 88 | 89 | - (void)setAlignment:(UIImageViewAlignmentMask)alignment 90 | { 91 | if (_alignment == alignment) 92 | return ; 93 | 94 | _alignment = alignment; 95 | [self setNeedsLayout]; 96 | } 97 | 98 | - (void)layoutSubviews 99 | { 100 | CGSize realsize = [self realContentSize]; 101 | 102 | // Start centered 103 | CGRect realframe = CGRectMake((self.bounds.size.width - realsize.width)/2, (self.bounds.size.height - realsize.height) / 2, realsize.width, realsize.height); 104 | 105 | if ((_alignment & UIImageViewAlignmentMaskLeft) != 0) 106 | realframe.origin.x = 0; 107 | else if ((_alignment & UIImageViewAlignmentMaskRight) != 0) 108 | realframe.origin.x = CGRectGetMaxX(self.bounds) - realframe.size.width; 109 | 110 | if ((_alignment & UIImageViewAlignmentMaskTop) != 0) 111 | realframe.origin.y = 0; 112 | else if ((_alignment & UIImageViewAlignmentMaskBottom) != 0) 113 | realframe.origin.y = CGRectGetMaxY(self.bounds) - realframe.size.height; 114 | 115 | _realImageView.frame = realframe; 116 | 117 | // Make sure we clear the contents of this container layer, since it refreshes from the image property once in a while. 118 | self.layer.contents = nil; 119 | } 120 | 121 | - (CGSize)realContentSize 122 | { 123 | CGSize size = self.bounds.size; 124 | 125 | if (self.image == nil) 126 | return size; 127 | 128 | switch (self.contentMode) 129 | { 130 | case UIViewContentModeScaleAspectFit: 131 | { 132 | float scalex = self.bounds.size.width / _realImageView.image.size.width; 133 | float scaley = self.bounds.size.height / _realImageView.image.size.height; 134 | float scale = MIN(scalex, scaley); 135 | 136 | if ((scale > 1.0f && !_enableScaleUp) || 137 | (scale < 1.0f && !_enableScaleDown)) 138 | scale = 1.0f; 139 | size = CGSizeMake(_realImageView.image.size.width * scale, _realImageView.image.size.height * scale); 140 | break; 141 | } 142 | 143 | case UIViewContentModeScaleAspectFill: 144 | { 145 | float scalex = self.bounds.size.width / _realImageView.image.size.width; 146 | float scaley = self.bounds.size.height / _realImageView.image.size.height; 147 | float scale = MAX(scalex, scaley); 148 | 149 | if ((scale > 1.0f && !_enableScaleUp) || 150 | (scale < 1.0f && !_enableScaleDown)) 151 | scale = 1.0f; 152 | 153 | size = CGSizeMake(_realImageView.image.size.width * scale, _realImageView.image.size.height * scale); 154 | break; 155 | } 156 | 157 | case UIViewContentModeScaleToFill: 158 | { 159 | float scalex = self.bounds.size.width / _realImageView.image.size.width; 160 | float scaley = self.bounds.size.height / _realImageView.image.size.height; 161 | 162 | if ((scalex > 1.0f && !_enableScaleUp) || 163 | (scalex < 1.0f && !_enableScaleDown)) 164 | scalex = 1.0f; 165 | if ((scaley > 1.0f && !_enableScaleUp) || 166 | (scaley < 1.0f && !_enableScaleDown)) 167 | scaley = 1.0f; 168 | 169 | size = CGSizeMake(_realImageView.image.size.width * scalex, _realImageView.image.size.height * scaley); 170 | break; 171 | } 172 | 173 | default: 174 | size = _realImageView.image.size; 175 | break; 176 | } 177 | 178 | return size; 179 | } 180 | 181 | 182 | #pragma mark - UIImageView overloads 183 | 184 | - (void)setHighlighted:(BOOL)highlighted { 185 | [super setHighlighted:highlighted]; 186 | self.layer.contents = nil; 187 | } 188 | 189 | #pragma mark - Properties needed for Interface Builder 190 | 191 | - (BOOL)alignLeft 192 | { 193 | return (_alignment & UIImageViewAlignmentMaskLeft) != 0; 194 | } 195 | - (void)setAlignLeft:(BOOL)alignLeft 196 | { 197 | if (alignLeft) 198 | self.alignment |= UIImageViewAlignmentMaskLeft; 199 | else 200 | self.alignment &= ~UIImageViewAlignmentMaskLeft; 201 | } 202 | 203 | - (BOOL)alignRight 204 | { 205 | return (_alignment & UIImageViewAlignmentMaskRight) != 0; 206 | } 207 | - (void)setAlignRight:(BOOL)alignRight 208 | { 209 | if (alignRight) 210 | self.alignment |= UIImageViewAlignmentMaskRight; 211 | else 212 | self.alignment &= ~UIImageViewAlignmentMaskRight; 213 | } 214 | 215 | 216 | - (BOOL)alignTop 217 | { 218 | return (_alignment & UIImageViewAlignmentMaskTop) != 0; 219 | } 220 | - (void)setAlignTop:(BOOL)alignTop 221 | { 222 | if (alignTop) 223 | self.alignment |= UIImageViewAlignmentMaskTop; 224 | else 225 | self.alignment &= ~UIImageViewAlignmentMaskTop; 226 | } 227 | 228 | - (BOOL)alignBottom 229 | { 230 | return (_alignment & UIImageViewAlignmentMaskBottom) != 0; 231 | } 232 | - (void)setAlignBottom:(BOOL)alignBottom 233 | { 234 | if (alignBottom) 235 | self.alignment |= UIImageViewAlignmentMaskBottom; 236 | else 237 | self.alignment &= ~UIImageViewAlignmentMaskBottom; 238 | } 239 | 240 | - (CGSize)sizeThatFits:(CGSize)size { 241 | return [self.realImageView sizeThatFits:size]; 242 | } 243 | 244 | 245 | @end 246 | -------------------------------------------------------------------------------- /docs/IBsetup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reydanro/UIImageViewAligned/9f6bc486026064242133c21715220bbc34bffa51/docs/IBsetup.png --------------------------------------------------------------------------------