I am struggling with a basic beginners problem at the moment. My app should run on all the different iPhones. My problem right now is that my constraints are not really responsive.
Examples:
As you can see on the iPhone 11 everything looks perfectly fine but on the iPhone 6s it a bit messed up sometimes.
My question, is there an easy way to make my design responsive? Not just the constraints but also text (e.g. "Main Wishlist" in the 3rd picture).
By the way I am doing everything programmatically. Any help on this is appreciated :)
Using the Dynamic Type you can solve the dynamic font problem
Here is an example of how you can scale your Fonts Automatically based on the content size using the Dynamic Type:
guard let customFont = UIFont(name: "CustomFont-Light", size: UIFont.labelFontSize) else {
fatalError("""
Failed to load the "CustomFont-Light" font.
Make sure the font file is included in the project and the font name is spelled correctly.
"""
)
}
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: customFont)
label.adjustsFontForContentSizeCategory = true
https://developer.apple.com/documentation/uikit/uifont/scaling_fonts_automatically
Using the Auto Shrink Property
follow this accepted answer
Scale text label by screen size
Related
We have a situation where if a user decides to increase the "Larger Text" size in iOS Settings (see image below), it then messes up our view layouts in React Native, as the font size will now be larger.
For example here is a ListView row BEFORE changing the "Larger Text" setting in iOS system settings:
And here is the same row AFTER increasing the "Larger Text" setting:
What is best practice to handle such font scale increase in React Native ? This is obviously just one example, and there are other scenario's such as a View that only contains Text, but we do not want to increase the height of that View at runtime.
Appreciate anyone's advice on this, thanks!
You can do the following to block such changes (do it on your root js file):
Text.defaultProps.allowFontScaling = false;
you could use ITEM_SIZE * PixelRatio.getFontScale()
I am trying to change the font size based on the iPhone Screen size.
I am setting a font size that looks good on iPhone 6 Plus and once I detect the iPhone and it is not iPhone 6 Plus, I change its size.
I am trying it on the ViewDidLoad event:
lblLogin.Font.WithSize(17f);
But it is not updating the FontSize, I guess "Font.WithSize" is not the path to achieve it, any ideas?
WithSize() returns a font reference, it does not modify the existing font
lblLogin.Font = lblLogin.Font.WithSize(17f);
Also, see this Xamarin recipe
If you want to change the font size of a UILabel, try to use those code, like:
//1 Just change size
customLabel.Font = UIFont.SystemFontOfSize (18);
//2 Set the font name and size:
customLabel.Font = UIFont.FromName("Helvetica-Bold", 20f);
Hope it can help you.
i am searched in stackoverflow, regarding font problems in ios 9, but nothing to any related solution, so, i am post this question.
Question:
I am using UIStoryBoard to design a page, in this page i have using labels, textfields and extra... , my problem is I have provide "system font size XX" to labels and text fields text (Here i am using XCode 6.3 and iOS 8),
and run in iOS 8 Devices its display exact design(means, the what i am design in storyboard).
but i am run in iOS 9 its font size increases, what the problem.
==> In iOS 8 device, the Label text is displayed exactly what i am design
For example
[] --> let, this is label , here i am design like this,
" [2015] "
Size of Label is: 55
Label text font size : system 17
==> In iOS 9, Here missing the content like this,
" [20...] "
Size of Label is: 55
Label text font size : system 17
So, i am thinking Label font size is increased.
please, suggest any solutions or fixes.
Thanks.
iOS9 now has a new System Font called "San Francisco"
I believe your labels are only fitting for the previous system font "Helvetica", so your labels are truncating the tail.
You can fix this by setting the minimum font size in Interface Builder or via code as such:
let label = UILabel()
label.minimumScaleFactor = 10.0/12.0
You can find more informtion on the new iOS9 system font here: https://developer.apple.com/fonts/
It seems that the font in iOS9 is bigger. If you dont't want to change the font size or set minimumScaleFactor, you can change label.adjustsFontSizeToFitWidth = YES. But you'd better put it at last of label creation code just before you add the label to some view
I'm currently working with the following : Swift (1.2), Xcode (6.3) and iOS 8.3.
I currently have an application that look similar to this sample I've made for this question :
For each UIButton / UILabel I would like to configure their font size depending on which device is used (iPhone 4s to iPhone 6 Plus for example).
As you can see I tried to use the "text-displaying control" in order to add a large font size (44) and another one smaller (33). For this second one, the setting is on "Width: Compact ; Height: Any".
Below are my current results :
However, as you can see, the font on the iPhone 6 Plus is still the little one. I tried to change the settings (of the little font) for "Width: Compact ; Height: Regular" and with the System font ; but the result is the same :(
How could I have something like this (iPhone 6 Plus with the large font size) ?
Is there a way to :
target specific devices with AutoLayout directly within the storyboard ?
use some tricks to make it look great (maybe with constraints and minimum font scale) ?
do it outside the storyboard (through the code) ? The only solution is to check the value of UIScreen.mainScreen().bounds.size.width ?
I just went through something like this with one of my own apps, and settled on this solution:
// global utility...
var on6plus : Bool {
return UIScreen.mainScreen().traitCollection.displayScale > 2.5
}
// and then, in my view controller's viewDidLoad...
if on6plus {
for lab in [self.scoreLabel, self.prevLabel, self.stageLabel] {
let f = lab.font
lab.font = f.fontWithSize(f.pointSize + 2)
}
}
I have some static Label with static text that will not change forever.
I adjust the layout in Interface Builder until they look great. and use Cmd + = to let all label's size fit their contents.
But when I run and test them on emulator and device they become truncate even though they look fit in the Interface Builder.
I have test it on iOS 5.0, 6.1 and on 3.5, 4 inches include on iphone5 device. All the result are different from in Interface Builder.
Emulator
Interface Builder
Any help to overcome this?
Thanks
You can try using this code for fitting the label content.
For that you need to have a IBOutlet for the label and then after that,
use this code when you load the view :
[self.label sizeToFit];
Hope that works !
As there's a change in DateFormatter it's creating a problem. In your XIB, date is in different format than your device.
You can set Minimum Font Size for your label from your XIB. Check below screenshot.
I hope it'll solve your problem.
Thanks,
Hemang.