diff --git a/UIImageViewAligned/UIImageViewAligned.h b/UIImageViewAligned/UIImageViewAligned.h index 8280b93..c22d99a 100644 --- a/UIImageViewAligned/UIImageViewAligned.h +++ b/UIImageViewAligned/UIImageViewAligned.h @@ -38,6 +38,11 @@ typedef UIImageViewAlignmentMask UIImageViewAignmentMask __attribute__((deprecat @property (nonatomic) BOOL alignTop; @property (nonatomic) BOOL alignBottom; +@property (nonatomic) CGFloat insetLeftPercentage; +@property (nonatomic) CGFloat insetRightPercentage; +@property (nonatomic) CGFloat insetTopPercentage; +@property (nonatomic) CGFloat insetBottomPercentage; + // Make the UIImageView scale only up or down // This are used only if the content mode is Scaled @property (nonatomic) BOOL enableScaleUp; diff --git a/UIImageViewAligned/UIImageViewAligned.m b/UIImageViewAligned/UIImageViewAligned.m index d153105..8cf0cf8 100644 --- a/UIImageViewAligned/UIImageViewAligned.m +++ b/UIImageViewAligned/UIImageViewAligned.m @@ -97,20 +97,22 @@ - (void)setAlignment:(UIImageViewAlignmentMask)alignment - (void)layoutSubviews { + [super layoutSubviews]; + CGSize realsize = [self realContentSize]; // Start centered CGRect realframe = CGRectMake((self.bounds.size.width - realsize.width)/2, (self.bounds.size.height - realsize.height) / 2, realsize.width, realsize.height); if ((_alignment & UIImageViewAlignmentMaskLeft) != 0) - realframe.origin.x = 0; + realframe.origin.x = 0 - (self.bounds.size.height * self.insetLeftPercentage); else if ((_alignment & UIImageViewAlignmentMaskRight) != 0) - realframe.origin.x = CGRectGetMaxX(self.bounds) - realframe.size.width; + realframe.origin.x = CGRectGetMaxX(self.bounds) - realframe.size.width + (self.bounds.size.height * self.insetRightPercentage); if ((_alignment & UIImageViewAlignmentMaskTop) != 0) - realframe.origin.y = 0; + realframe.origin.y = 0 - (self.bounds.size.height * self.insetTopPercentage); else if ((_alignment & UIImageViewAlignmentMaskBottom) != 0) - realframe.origin.y = CGRectGetMaxY(self.bounds) - realframe.size.height; + realframe.origin.y = CGRectGetMaxY(self.bounds) - realframe.size.height + (self.bounds.size.height * self.insetBottomPercentage); _realImageView.frame = realframe;