Skip to content

Instantly share code, notes, and snippets.

@BrightScreenTV
Forked from KiranPanesar/NTVImageView.h
Created July 3, 2023 08:20
Show Gist options
  • Save BrightScreenTV/6d12c6eee7bb79205accb1475e4e824c to your computer and use it in GitHub Desktop.
Save BrightScreenTV/6d12c6eee7bb79205accb1475e4e824c 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