Reducing the height of NSProgressIndicator from interface builder - objective-c

I am new to cocoa development.
Is there a way to reduce the height of a NSProgressIndicator from interface builder? I see the height is grayed out on 19 pt there!
I see also a size property with small and regular but what about I creating my own size?

I was not working with NSProgressIndicator but I worked a lot with UIProgressView (iOS analog of NSProgressIndicator). And it is impossible to change UIProgressView's height neither in IB neither by changing its frame property.
But there is a nice workaround! In iOS you can use transform property to change the height. Following will reduce height by 50%:
_progressView.transform = CGAffineTransformMakeScale(1.0f, 0.5f);
Maybe you can use the same workaround for NSProgressIndicator.

Related

How to set an image to a NSButton to be resized along with the button?

I have an image (3width x 15height, the first and last pixels are rounded on the corners), and I want to create a button (the height of the button is always the same, 15px, but the width changes) that uses this image no matter what size it is, kinda like UIEdgeInsets on iOS.
I've tried to use [[button cell] setImageScaling:NSImageScaleAxesIndependently]; but the image gets distorted and loses quality.
How can I do this on OSX? Thanks!
You could probably create a custom subclass of NSButtonCell and use the Application Kit's NSDrawThreePartImage() function in the cell's drawInteriorWithFrame:inView: method.
For more info on how to use NSDrawThreePartImage(), see Cocoa Drawing Guide: Drawing Resizable Textures Using Images.
If it's possible to set this in graphical interface > Attribute Inspection > Button section Background

Autoresize Height and Width Proportionally Interface Builder

I have a UIImageView that is set to autoresize it's height based on the height of the Superview, i.e. when the In Call Status bar comes down. How do I make the entire view resize proportionally so that the width of the UIImageView changes when the height changes?
I would like to do this in Interface Builder, but programmatically can be used as well.
Thanks
The easiest way in iOS 6 is to use the (new in iOS 6) autolayout feature. It is very easy to make a view's width always be a fixed proportion of its height.
Otherwise you'll have to detect the change in your view controller's layoutSubviews and use code to resize the UIImageView.
However, consider the alternative of letting image resize rather than the whole image view. If you give the UIImageView the right contentMode, it will automatically resize the image proportionally if the view's height changes.

How can I use Autolayout to create a layout that expands in height based on the content of a UILabel

I am attempting to build a dynamic layout using the new autolayout api in iOS 6.0. The layout that I am attempting to build has 2 buttons with a label inbetween them as shown in the image below:
What I would like is for the container view shown in grey to increase or decrease in size depending on the amount of text in the label.
So far I've managed to get the layout to work exactly as described with one small issue that I've not been able to resolve. The problem I am having is that the intrinsic height of the label is alway calculated with the original width of the label (e.g. the one set in interface builder) and not the width of the label that is set from the constraints I have on it.
The constraints that I have on the views are as follows:
H:|-[leftButton]-[label]-[rightButton]-|
Both buttons are centered Vertically
V: |-[label]-|
the content hugging priority of the buttons is higher than the label
the compression Resistance of the label is higher than the container view
All of these constraints together create the desired layout.
However:
If the Width of the label in interface builder (the literal size in interface builder) is less than the width of the view at runtime, then the height of the container is too large.
To help clarify this, the IB view of the above layout was as follows (note much narrower)
If the Width of the label in interface builder (the literal size in interface builder) is greater than the width of the view at runtime, then the height of the container is too small and lines of text get cut off.
What appears to be happening is that although there is no constraint on the labels width, the label seems to calculate its height (and thus the autolayout calculated height of the container) based on the original width of the label when it was created. However whats so strange is that the text appears to be the correct width and height but the label itself has a frame thats just too big or small.
I guess this is related to the order in which things are happening, and have tried calling updateConstraintsIfNeeded in the containerViews layoutSubview method however this doesn't appear to do anything.
Any suggestions would be greatly appreciated.
May be I am late but any way I've found solution. Any time when label width is changed you need to manually update preferredMaxLayoutWidth for Label. For example:
Label.preferredMaxLayoutWidth = 200;
Interface builder sets preferredMaxLayoutWidth with initial label width.
Hope this helps.
Have you tried calling -invalidateIntrinsicContentSize on your label?
Yes, -invalidateIntrinsicContentSize can also be used for this.
Make a Custom Class like 'CustomLabel'.
Set this Class for UILabel in interface builder.
Override the functions which returns the IntrinsicContentSize
-(CGSize)intrinsicContentSize {
//If the width is Zero.
if (self.frame.size.width == 0) {
return [super intrinsicContentSize];
}
return [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(self.frame.size.width, MAXFLOAT)];
}
Inform the system, to reCalculate it's Intrinsic Size by calling the method.
[CustomLabel invalidateIntrinsicContentSize];
Hope this would help.

clipToBounds and masksToBounds performance issue

I have UIScrollView and number of objects (UIView compositions) with UIImageViews inside them. Some of UIImageViews has round border (I use myImageView.layer.masksToBounds = YES; for this). Other has rectangle borders and part of image in them (I use Clip subviews property in Interface Builder for this).
The issue is that I found that clip properties strongly affect the performance while scrolling:
For iPod touch (4th generation) results of profiling:
with enabled clip properties (both or one of them) I have around 30 fps while scrolling
with disabled clip properties I have all 60 fps while scrolling
I really need to clip some images to round bounds and other to rectangle bounds (to show part of image). So, here is my question: what ways there are to improve performance? May be there are low level ways to do it (drawRect: or something), or may be it would be useful to play around alfa masking or I just do something wrong?
When you have graphically intensive masks and things, a simple and easy way to improve performance (often times dramatically) is to set shouldRasterize to YES on the layer for that item:
#import <QuartzCore/QuartzCore.h>
// ...
view.layer.shouldRasterize = YES;
This will rastersize the view into a buffer, so it isn't constantly re-rendered. This will take up a extra memory for each view, so you should really try and recycle/reuse views as you scroll, similar to how a table view does.
For correct behaviour on retina display you also need to set an appropriate value for rasterizationScale:
view.layer.rasterizationScale = view.window.screen.scale; // or [UIScreen mainScreen]
I've had great success with this for things like scrolling photo galleries, where each item had rounded corners, shadows, etc.

scalable windows in os x

i'm trying to create a window that can be scaled, just like the iPhone/iPad simulator. in the iPad simulator, you can select Window > Scale and select either 100% or 50%.
is there a way to make an NSWindow do this? i've looked at applying scaleUnitSquareToSize to the window's contentView but no matter what i do in InterfaceBuilder, the contentView keeps resizing itself to fill the window. is this the correct behavior even after removing all struts for the contentView?
This is a great open source implementation of a zoomable NSView:GCZoomView
the contentView keeps resizing itself
to fill the window
The content view's autoresizing behavior has nothing to do with the unit square's scale factor.