Skip to content

Instantly share code, notes, and snippets.

@KiranPanesar
Created October 27, 2015 15:57
Show Gist options
  • Save KiranPanesar/f0dfa5a7c50c1c66d603 to your computer and use it in GitHub Desktop.
Save KiranPanesar/f0dfa5a7c50c1c66d603 to your computer and use it in GitHub Desktop.
A UIImageView subclass which allows for external memers to set the intrinsicContentSize
//
// NTVImageView.h
//
// Created by kiran on 27/10/2015.
//
#import <UIKit/UIKit.h>
@interface NTVImageView : UIImageView
/**
* A property to constrain the contentSize of the receiver.
*
* This will automatically call `invalidateIntrinsicContentSize` on the receiver
* to trigger a layout pass.
*/
@property (assign, nonatomic, readwrite) CGSize constrainedSize;
@end
//
// NTVImageView.m
//
// Created by kiran on 27/10/2015.
//
#import "NTVImageView.h"
@implementation NTVImageView
- (CGSize)intrinsicContentSize {
return self.constrainedSize;
}
- (void)setConstrainedSize:(CGSize)constrainedSize {
_constrainedSize = constrainedSize;
[self invalidateIntrinsicContentSize];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment