2 UIButtons with different text lenght same font size - ios

I have 2 buttons with the same width and height, also y-Achse centered. They differ only from text length. With iPhone 5, 6 and 6+ they look very well. But with iPhone 4s one button will do not more have the same front size as the other one and it is text will be not more centered. My question is if there is a method to adopt the font size of the 2 buttons so they will take together the same font with small value of font size of one button.

If I understand correctly, you want to use the same font size for both buttons, even when one of them has to reduce the size for the text to fit it.
Use something like this to reduce the size of the font on each button, until an appropriate size is found for both buttons. Take the minimum of the sizes you found, and use it on both buttons.

Related

Autoshrinking text size for multiple ui labels

I have five ui labels for one view. All of them have variable text content. To prevent truncating I have to use Autoshrink text size.
My ui labels are aligned in x axis top to bottom.
The problem is; when autoshrinking, all ui labels have different font sizes.
Is there a way to equalize font sizes of all ui labels when autoshrink.
I use interface builder autolayout constraints.
Thank you.
You could loop through your labels, find the smallest text size and then set that text size to all of them. That way, you know they'll all fit and have the same text size. You would have to do this programmatically. Alternatively, you could dynamically change the size of your UILabels based on the number of characters it holds times some constant factor. That way, the autoshrink should set the same size for each the text in each of the labels.

Different font Textsizes for different devices in Xcode 6 [duplicate]

I want to fit my text in a UILabel, but for different iPhone the size of the UILabel is changing, as I'm using auto layout, but I cannot fix the font size, so my text is cutting out.
Is there any way I can set any constraint so that the text fits in the UILabel dynamically?
See here the text got cut, because of different screen resolution
You should use autoshrink.
Since all iPhones have the same Compact width size class when in portrait mode, you can't rely on this to handle your label size.
Previews are for iPhone5, iPhone6 and iPhone 6+
In the inspector, you must select minimum font scale or minimum font size in front of Autoshrink. This enables the content to change the size of the font to fit in the label.
Here, I set minimum font scale to 0,5 so the minimum size is half of the current size (31.0). The text will try to fit until it reaches the minimum scale/size.
(Generally do not use "Tighten letter spacing" for this purpose. Tighten letter spacing uses the same font size and reduces spacing between letters. It can make the label up to 5% tighter before truncating, but it's not effective when minimum font scale/size is enabled.)
You may want to test with a wide screen device such as the iPad Pro, and also on a smaller screen such as the iPhone 4S. As a good practice you should test with different user system font sizes, you can set them in Settings>General>Accessibility>Larger Text.
Autoshrink will not adjust the font size bigger than the one set on the label, that means if you make the label the same width as the screen but leave the font size to 14, it will try to increase the font size until it reaches that size.
To make it actually work, select a big font size.
You can still combine autoshrink with size classes to change the maximum font size depending on the device/the orientation.
In case you want to use autoshrink with UIButtons, you can still set this behavior with two lines of code.
myButton.titleLabel.minimumScaleFactor = 0.5;
myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
Hi if you are adding UILabel from storyboard you can set different font for all available layout.
You can do this by using size classes.
each display dimension using a size class, this will result in four abstract devices: Regular width-Regular Height, Regular width-Compact Height, Compact width-Regular Height and Compact width-Compact Height.
The table below shows the iOS devices and their corresponding size classes.

To set the font size for this particular size class, first select the UILabel. Under the Attributes inspector, you should see a plus (+) button next to the font field. Click the + button and select Compact Width > Regular Height (Or as per your requirement select width & Height). ​ You will then see a new entry for the Font option, which is dedicated to that particular size class. Keep the size intact for the original Font option but change the size of wC hR (OR as per your selection) font field to required points (for example 14).

How to increase the font size in propotion to view height

I am increase Textview height in propotion to parent view but font size remains same.
I would like to change the font size accoring to textview or screen size so it fills up the space in textview
The problem I am facing is in iPhone 4s it fills up the space while iphone 7s there are lots of empty space
is there any constraint we can use to achieve that other than doing programtically.
If you use a UILabel instead of a UITextView, you can set the Font Size to very large, with a small Minimum Font Scale. Then, your text will "auto-size" to fit the view.
In this example, the Font is set to System 100.0 --- really, really big. Autoshrink is set to Minimum Font Scale with a value of 0.1 - or, 1/10th of 100, which is 10, and that's probably as small as you would want it to get.
While designing your view in Interface Builder, you will see the font size change as you change the size of the view.

Update multiple UILabel/UIButton font sizes by constant value

I want to be able to increase/decrease the size of several the label/button fonts on my storyboard by the same amount. As far as I know sizes can be changed when selected (though as labels or buttons separately) and adjusted but each is updated by one font value not say a percentage. Ideally I'd like to select all labels and buttons and enter a value to times them by (e.g 1.4x). Is there definitely no way of doing this?
I used the label multipliers to create percentage view sizes and auto shrink to resize the text to be proportionally sized.

UILabel: 2 lines text shrinking

By design (!) I have two lines title text which I cannot break:
JustWord
VeryLongWordWithoutSpaces
On big iPhones (6 and 6 Plus) text works great,but when I test on smaller iPhone (5 or less) it looks like:
JustWord
VeryLongWordWi...
I cannot find a way how to shrink the text in UILabel.Cutting and truncating are not possible in my situation.
Requirements:Auto Layout, no Storyboards, Swift 2.0, iOS 8.0+
Please try adjustsFontSizeToFitWidth: property for UIlabel. I have tried this and font is setting in one line and font size is automatically adjust.
The two principal ways to do this are to set a minimum font size or a minimum font scale.

Resources