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.
Related
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
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 try to clone a placeholder behavior for a tableCell. It must look exactly like the placeholder used within a UITextField. Does anybody know which Font is used by Apple as well as which Font size?
Thanks
The default font in UITextfield is HelveticaNeue 14
I just upgraded to xcode 4.5 with iOS 6.0 and it's highlighting a warning on all the UILabels in my XIB files saying "minimum font size deprecated on ios version 6.0". Does anyone know what this is referring to and how to fix it?
Update:
image is no more available (was at https://skitch.com/hahmadi82/eyk51/cloud)
minimumFontSize property of the UILabel is deprecated from iOS 6.0 onwards.
An Alternative to the minimumFontSize is minimumScaleFactor. If you assign minimumFontSize/defaultFontSize to minimumScaleFactor, it works in the same way as minimumFontSize.
The Code is as follows - For Example the font size is 30.0 and if you want the minimum font size to be 12.0
YOURLABEL.font= [UIFont fontWithName:#"FONT_NAME" size:30.0];
[YOURLABEL setMinimumScaleFactor:12.0/[UIFont labelFontSize]];
Use minimumScaleFactor instead...
Link
Quick fix...Here minimum font size to be 8.0
CGFloat size = textLabel.font.pointSize;// font size of label text
[textLabel setMinimumScaleFactor:8.0/size];
I am answering very late, but might help any other.
As every one knows that setMinimumFontSize has been deprecated, so other method replacing setMinimumFontSize is setAdjustFontToFitWidth which takes BOOL
e.g
[yourLabel setAdjustsFontSizeToFitWidth:YES];
//or
yourLabel.adjustsFontSizeToFitWidth = YES;
For Swift use the following:
//set the number (ex. 8 to your desired minimum font size)
myLabel!.minimumScaleFactor = 8/myLabel!.font.pointSize;`
Works like a charm!
I had similar problem. Quick fix is to use MinimumScaleFactor property of UILabel.
Go into finder and find the .storyboard file or your .xib and open with TextEdit. Use find to locate the string "autoshrinkMode" and replace the value "minimumFontSize" to "minimumFontScale"
Odd that the conversion wasn't written in the update scripts...
Also credit to #Rob in the comments above for stating the same answer. He should receive credit for this one.
You can use minimum scale factor over there or drag a lable and set autoshrik-> minimum font.
Maybe this can help you.
Yes minumumFontSize is deprecated.
Use following minimumScaleFactor:-
Obj.minimumScaleFactor= (floatValue);