I am developing an app, that has support for customizing fonts, colors etc. in design time.
You just swap a plist and the app has a different style,color,s etc..
This works, i need to have it like that . So far so good.
Some buttons have titles. I use two different custom fonts for two different builds.
The problem is, using the other font causes the titleLabels in all buttons to be offset 5 point to the TOP.
I can't use some "hacky "way to move the offset 5 px up. Since it wll coause the first font to be offset 5 px up.
I am not really sure if the problme is in my code, or in the source font file.
The label is centered horizontaly and verticaly. Is there any other way to generalize the code so that it would handle that offset difference?
compare like this:
CGSize firstStringSize = [myString sizeWithFont:firstFont]; //get size for first string with its font
CGSize secondStringSize = [myString sizeWithFont:secondFont]; //get size for second string with its font
if(!CGSizeEqualToSize(firstStringSize, secondStringSize)) //checking for both are not equal
{
if(firstStringSize.height > secondStringSize.height)
//secondStringSize offset 5 px
if(secondStringSize.height > firstStringSize.height)
//firstStringSize offset 5 px
}
Related
I want to draw single line textfield with default border.
So I entered some multiline text into it(just for test for future cases) and set the flags
Swift:
textfield.usesSingleLineMode = true
textfield.maximumNumberOfLines = 1
Objective-C:
self.textfield.usesSingleLineMode = YES;
self.textfield.maximumNumberOfLines = 1;
But I got in console:
(lldb) po self.textfield.intrinsicContentSize
(width = 511.5, height = 174)
I've tested all lineBreakModes, including NSLineBreakByTruncatingTail.
Here is a field in IB:
Of course I can:
Overload intrinsicContentSize method
Filter strings keeping only first line
But it looks like a crutch =( Do you have any ideas how to fix it without crutches? Do you think it is an AppKit bug or my mistake?
PS In any case, thanks for attention.
This is not a bug. By default the NSTextField is trying to display as much text possible. I made a sample application, that contains a long line of text in the title of the NSTextField. Set it to "Uses Single Line Mode" and set line break to "Truncate Tail". I put leading, top and trailing layout constraints on the view. Now when i input the text into the text field, it will make the horizontal width of the window very wide. This is Autolayout in action.
To fix this you need to select the NSTextField, choose the Size inspector and set the Horizontal Content Compression Resistance Priority to a lower number. In the sample application I changed it from 750 to low (250).
Resize content view to an acceptable size, and you are off to the races.
I'm working with a jsx script in Photoshop that resizes images to a specific size. The resolution is set at 200 dpi. After running the script, I can check this under Image > Image Size.
Problem is, depending on the image, it initially tends to show the resolution in dots/cm instead of dots/inch. The number itself is correct either way, but I'd like to see it mentioned there as the latter. Is there a way to realize this in JSX?
Thanks!
J
The easy way is to open your Info Panel by going to Window > Info, and then click on the x/y coordinates dropdown in the Info Panel and select inches. The dropdown is the + toward the lower-left of the panel, with the little down arrow at the bottom right of the + symbol (The plus is actually an x axis and y axis representing a coordinate plane). After that, when you check under Image > Image Size, it should show you all information in inches instead of centimeters. This should also show you inches anywhere else you look in Photoshop's interface, too, such as the rulers.
An exception would be that when using selection tools, such as the marquee tool with a setting like "fixed size" selected, you can override the units setting by typing in another unit in the Width and Height sections at the top of the window. You can even mix and match units, making a precise selection that is, for example, exactly 250 pixels (px in the Width setting) by 30 points (pt in the Height setting). And when you check your image size, it should still show you results in inches.
And finally, to answer your question as it was asked, the following code will change your rulerUnits preference without opening the Info Panel.
#target Photoshop
preferences.rulerUnits = Units.INCHES;
Note that if you want to write other scripts, you can change the rulerUnits to whatever units the script calls for, and then at the end of the script put your units back the way you had them.
#target Photoshop
// Save the original rulerUnits setting to a variable
var originalRulerUnits = preferences.rulerUnits;
// Change the rulerUnits to Inches
preferences.rulerUnits = Units.INCHES;
//
// Do magical scripty stuff here...
//
// Restore the original setting
preferences.rulerUnits = originalRulerUnits;
// List of rulerUnits settings available
// Units.CM
// Units.INCHES
// Units.MM
// Units.PERCENT
// Units.PICAS
// Units.PIXELS
// Units.POINTS
I’m trying to put together what seems to be a simple case of two NSTextFields with dynamic width and fixed spacing in between. I cannot figure out an effective way to do so though.
I’m looking to get something like this:
The blue boxes are the NSTextFields. When more text is entered into one, it should grow and thus make the other one shrink, maintaining the lead space, trailing space and the spacing in between the fields. The first one should take the priority if both of the fields have too much text. Each field will also clearly have a maximum and a minimum possible width it can reach.
How would I go around handling this, preferably utilising IB autolayout as much as possible?
It seems to me that all of constraints you mentioned directly translate into interface builder --
First view has width >= something.
First view has width <= something
Same for Second view.
Space between views is fixed.
Second view wants to be as small as possible (have its width at 0) but this has lower lower priority than the previous constraints and lower priority than inner content size constraints.
The code I had to add to my view controller, after applying the constraints as per the ilya’s answer:
In controlTextDidChange (_controlWidthConstraint refers to the fixed width constraint of the input; it’s probably 0 by default for the second input):
// Get the new width that fits
float oldWidth = textControl.frame.size.width;
[input sizeToFit];
float controlWidth = textControl.frame.size.width;
// Don’t let the sizeToFit method modify the frame though
NSRect controlRect = textControl.frame;
controlRect.size.width = oldWidth;
textControl.frame = controlRect;
_controlWidthConstraint.constant = controlWidth;
The key lies in invalidating the intrinsicContentSize for the text field when text is input.
You can check a sample project here, to get you on the right track.
I have designed my help page for my application,it contains some FAQs..so I have used UILabels for question and answer,I have adjusted,x,y,width and height exactly in the xib,leaving a gap between a question and answer and answer and next question.so totally I have some 10 question and answers,I have put them inside a scroll view.
But now, suppose the text changes dynamically, how can I adjust the positions and width and height,is a problem which I am not able to figure out, by using the below code,it adjusts the height and width of a particular label,if the text increases
NSString * test=#" It may come as a rude shock, but Facebook users should not feel surprised if tomorrow they come across their photos existing in the web world despite having deleted them personally long ago.";
m_testLabel.text = test;
m_testLabel.numberOfLines = 0; //will wrap text in new line
[m_testLabel sizeToFit];
but then, my next label will clash with it..is their any way so that all the labels get adjusted according if the width of any label increases or decreases?
Hope you all have understood my question..
Did you look into the below function, pass the font you have used and the size to which u want to constraint the label into.
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size
I've been trying to make my scrollview correctly fit it's content which includes a label, UIImageView, and textview. The textview sizes dynamically to different text, so I've made the scrollview's content size the same as the textview's:
sview.contentSize = (tview.contentSize);
That worked as expected, so my scrollview is close to the size I want, but I need to just add a static 180 pixels or so to make up for the label and image, which don't change size. I would guess it's an easy 1 or 2 lines of code but I can't figure it out. I've tried:
sview.contentSize += 180;
and
CGRect extra;
extra.size.height = 180;
sview.contentSize += extra.size;
and several other combinations to try to make it work but I keep getting errors like Lvalue required as left operand of assignment, or invalid operands to binary +. I'm sure I'm missing an easy solution, thanks for any help.
sview.contentSize = CGSizeMake(sview.contentSize.width, sview.contentSize.height+180);