I have a NSView, there is a NSImageView on the NSView
in the source codes of the NSView
I wrote:
NSImage *image = [[[NSImage alloc] initWithContentsOfURL:url] autorelease];
NSImageView *newImageView = nil;
newImageView = [[NSImageView alloc] initWithFrame:[self bounds]];
[newImageView setImage:image];
[newImageView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
Is there a way to read the width and height of the NSView and NSImageView?
The size of any view (NSView, NSImageView, etc.) is view.frame.size
or view.bounds.size
.
In both cases it is an identical NSSize
struct. You can write code like this:
NSSize size = newImageView.frame.size;
NSLog(@"size: %@", NSStringFromSize(size));
NSLog(@"size: %f x %f", size.width, size.height);
To change it, you need to update the view frame
property:
NSRect frame = view.frame;
frame.size = NSMakeSize(<#new width#>, <#new height#>);
view.frame = frame;
Try the - (NSRect)bounds
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With