I'm currently building an iOS App in Swift and I got some problems. My settings view is a tableviewcontroller. It's a grouped one. My Table View is dynamic, fonts are dynamics.
I would like to interact to the change of font size from the settings app.
If my application was already running, the font size change but the layout is just broken. (change from the smallest to the biggest font)
Image : Layout bug
If I restart my app with the new font settings, there is no problems...
Here is a XCODE project example, you'll see the bug.
Could you please help me to find a solution ? Thanks.
The UIContentSizeCategoryDidChangeNotification is what you're looking for.
Per the docs:
Posted when the user changes the preferred content size setting.
This notification is sent when the value in the
preferredContentSizeCategory property changes. The userInfo dictionary
of the notification contains the UIContentSizeCategoryNewValueKey key,
which reflects the new setting.
Example callback implementation:
func handleContentSizeCategoryDidChangeNotification(notification: NSNotification) {
self.questionLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
}
After you change the font size try to call
self.view.setNeedsLayout()
it sets a flag in the UIView that marks it as needing layout change.
Also you can try to call
self.view.layoutIfNeeded()
Apple documentation says :
Use this method to force the layout of subviews before drawing. Using the view that receives the message as the root view, this method lays out the view subtree starting at the root.
Hope that help you
Finally, I found that it's an iOS bug. I find the same bug in the Apple Apps.
The bug happens when you set the smallest font, quit the app and set the biggest font.
Thanks for your help.
Bug Settings App
Related
According to this article:
https://useyourloaf.com/blog/restricting-dynamic-type-sizes/
And this WWDC 2021 video:
https://developer.apple.com/videos/play/wwdc2021/10059/?time=879
The minimumContentSizeCategory and maximumContentSizeCategory can limit the min and max font size when user uplevel/downlevel the font sizes in System Accessibility settings.
However I tried it out, and from the debugging info these two settings are properly set, but in view rendering, the font size still goes to very large if accessibility font size is very large.
// before setting
print(label.appliedContentSizeCategoryLimitsDescription)
label.minimumContentSizeCategory = .small
label.maximumContentSizeCategory = .accessibilityMedium
// after setting
print(label.appliedContentSizeCategoryLimitsDescription)
print results:
UILabel:0x7fd610a414a0: AX-L
--> AX-L
UILabel:0x7fd610a414a0: S <= (none->)AX-M <= AX-M
--> AX-M
How can I properly use these two settings?
Any ideas on how to properly use these two settings?
I hope that's the proper way because I use them as you did (and it works).
I created a blank project in Interface Builder (Xcode 13.4.1) as follows:
... and the Dynamic Type feature is blocked within the specified thresholds I defined like you (in the viewDidLoad of the view controller).
I think you should check out the way you created your label because, with the above one, it works like a charm.
I am working on an iOS app right now. I usually use the Interface Builder and recently it has been producing an issue. When the storyboard is seen in Xcode the labels on everything look fine, but some UI elements don't render properly at runtime. This has also happened for some of the images in this project. The only font used is the system font.
I have tried readjusting the font and using attributed text, but this hasn't worked for the specific label shown. Just to mention, this app is a shared project through Git so it may be an issue with it pulling incorrectly or something, but that seems odd for it to affect the text after it has been changed and adjusted.
View post on imgur.com
The results should be crystal clear text on iOS, but it results in "fuzzy" text you would expect if you were running the Windows XP on a 480p screen. What could be causing this issue?
It seems like the layer of a superview of the UILabel in the provided image is set to pre-render. This is good for performance reasons but may not always look as good, as is seen here.
If you're setting a custom layer on a superview of the UILabel, try setting the layer's shouldRasterize to false.
Ex: exampleLayer.shouldRasterize = false
I'm a little confused when seeing the new interface builder's size class options in Xcode 8 beta. I used to build my apps' UI by first design them in "Any" size class and then do some custom adjustments in the other ones. Is the workflow supposed to be changed in this new version of Xcode?
The UI to select the size classes has changed in xcode 8. Now it is as follows:
Any constraints that you add without selecting Vary for Traits options will be considered as for all the size classes( Any Any previously)
To add a constraint to a specific size class add it by selecting:
The device at the bottom and by selecting Vary for Traits
options of that size class.
When you are adding constraints to a specific size class the bar
turns blue as below
The way to do this has changed slightly in the new version of Xcode. It should build for "any-any" automatically. Have a look at this WWDC video that I think explains it in detail. There is also a part 2, so watch that if you need to.
https://developer.apple.com/videos/play/wwdc2016/222/
Hope I could help,
Zack
To convert from the old Any by Any to the new Trait layout, go through each of your View Controllers and update all frames.
I am new to IOS development. I am developing an app for IOS 8 devices. I used storyboard for my design yesterday my storyboard showing all UI design but today morning it show blank UIViewController no UI element vision please see in screen shot and very strange thing is that when i run my app all ui element visible in my device. I google but dont find any solution please help me out. Thank you in advance.
It looks to me like you are using size class and you went into a particular size class and added these views. Now you are back in Any size class, so the views are not there (that is why they are greyed out in the document outline at the left). They are available only for that particular size class. If you switch back to it again, whatever it was, you will see them again. Basically, you have created conditional views - the condition being that they are present only when that particular size class situation is the case.
In other words, if you want your layout to apply in the general case, you want to start by creating and editing it under Any size classes. Only then do you switch to a particular size class and modify the layout for that particular size class.
when i run my app all ui element visible in my device
Yes, because on your device the particular size class situation matches the size class you were editing when you added those views. So there they are. That seems to me to prove my guess is right.
I have the same issue while copy a ViewController to another storyboard.
Fixed by following steps:
1: Select the viewController
2: Click on 5th Tab
3: Set the simulated size to Fixed.
Select install:
Since all components [like label,textfield,buttons] are in disable mode, one select Installed check mark its will be enable again adjust constrain accordingly.
The size must be the same, in all xcode storyboard
In my case, it was due to me setting alpha to 0.0 and forgetting it.
I have request from a client to match the "Large Text" font size set in the Accessibility section of the Settings app.
I found a post: But it doesn't actually gives an answer.
I also found this one : but its from last year.
Is there an API to access this feature?
Thanks in advance.
In iOS7 you get that for free with TextKit, and on UIApplication there's a property called preferredContentSizeCategory to access this value directly.