I've been working on a React Native app for the past few months, and something has always eluded me that I'm just now trying to get to the bottom of. I'm trying to standardize the font sizes within my app (for body, headers, etc.) and am struggling to understand where exactly React Native gets its default font size from. I've been testing in an iPhone 8 simulator running iOS 11, and through experimentation have come to the conclusion the default font displayed is 14 logical pixels (as in a brand-new element with no styling). However, checking the iOS style guidelines it would seem the default body text on iOS is intended to be 17pt. Although I don't a ton about device scaling, I've tried crunching the numbers in every online converter I could find, and could not come up with how 17pt may come close to 14 logical pixels (assuming RN uses the body font size by default). The only way I was able to roughly translate the two was if the DPI was around 90, but the DPI for iPhones is much, much higher. So might anyone be able to offer insight as to how default fonts are selected in React Native? Even hunting through the source code I couldn't find much. I'd like to be able to calculate the base size myself so I can scale the other font sizes according. Thanks in advance!
I suggest you to look at react-native-element's helper method normalizeText. It calculates the pixel ratio and set the texts fontSize accordingly.
Also you should also take in consideration of Accessibility Text Size Option in iOS. This option will be affecting all your app.
Related
Units of font size: I'm searching answers for the following, please help me to find it.
1. Which unit does Xcode use for font sizes? I mean, is it Pixels or Points or some other term?
One of the members of my designed team pointed at a label in iOS app that I'm working on and asked what is the font size of that label. What should I say? 12Px or 12Pt or just 12 (Saying a number without unit may lead to confusion)
2. Can we put the same Adobe XD font size for a UILabel in Xcode?
I'm developing iOS application UI from the designs in Abode XD. Which unit does Abode XD use for font sizes? I have tried to put the same font size(80) in Xcode, but it has slight differences, attached a screenshot. Do we need a conversion here?
According to this forum thread Adobe XD uses pixels:
XD currently uses a virtual pixel for most of its measurements (including font size), which should be the same unit of measure as a CSS pixel, or most measurements in iOS. It's roughly equal to 1 physical pixel on a 72 dpi monitor (and, incidentally, a point).
I'm not sure if this calculation is completely correct or not but after using it, the text size looks almost the same to me.
I was reading this discussion forum and found one image related to various measurements of a font. The unit of those fonts was in pt.
Then, I came across this table provided by W3schools
As you can see, px is 1/96th of 1 inch and pt is 1/72th of 1 inch. With this, we can form an equation like this -
Since we are provided pt value by Adobe XD, we can easily calculate the px value.
Maybe this can solve the issue of different font sizes. The one provided by Adobe XD is completely different from the one used in CSS.
I'm new to Xamarin and I'm actually developing an Android App. I've tried to run the app on different Android phones, but the fontSize appears either too small or large. Programmatically, how can I scale the FontSize of texts so that it can be adjust according to the device's screen?
Firstly, make sure you are using sizes in dp not px (or in, mm etc.) as these will factor in the screen density.
If you still have an issue, look at Screens support in the Android Docs, especially Using configuration qualifiers. Examples can be found here.
Basically you would need to provide a different resource file for each screen size. You should have a file something like res/values/dimens.xml where you store sizes for all your components. Make sure your font sizes are declared and referenced from here. You can then create a series of folders/files for the different screen sizes
res/values/dimens.xml
res/values-sw320dp/dimens.xml
res/values-sw720dp/dimens.xml
res/values-sw1024dp/dimens.xml
where each of these folders define the smallest width screen that that file will be used for.
I would like to ask a question about the highly confusing (at least to me) topic - Size Classes in Xcode 6. I have been trying to get a full understanding of how all this works, but it is still not clear to me.
Before Xcode 6 and the new iPhones, everything was very straightforward. To, Non-Retina and Retina, displays that enabled us to work with always same resolution 320x480 (or 568 for taller devices). Standard and #2x assets made perfect sense. Now however, we have the big ass screens with the same ratio (almost the same), but working area is not the same any more.
Size Classes are supposed to make things possible to fit all of it in one storyboard. But wait.. iPhone 6 uses #2x assets, which, in my understanding, means that the graphics will look smaller on that device than on iPhone 5/5S. And iPhone 6 Plus uses #3x assets, which again aren't gonna look the same. Seems like it is not possible to make, for example, a certain button always be of the same size in relation to, say, full width of the screen. Unless we code that of course, but that would make Size Classes useless.
Am I understanding things correctly or am I missing something? It would be great to hear how you all see it. Maybe you know some good tutorials? I haven't found anything that would explain my doubts.
Thanks in advance!
You can do much of what you're talking about here using a combination of different approaches:
Size classes for different types of devices to cover most large-scale changes in UI configuration (for example, differences between iPad and iPhone). You might use this to change whether a sidebar appears or not, for example.
Autolayout rules that are specific to individual size classes. You might add different autolayout rules for different size classes in order to tweak the layout (for example, you might switch between a horizontal row of buttons and a stacked column of buttons this way, since you can now have different Autolayout rules for different size classes). This technique is extremely powerful once you realize that you don't need to use the same autolayout rules for all size classes anymore.
Asset catalogs to switch out pre-rendered graphics for the different supported resolutions, etc, automatically. Note also that because many older devices don't actually support iOS 8, you don't need to include the really low-res versions anymore unless you need extensive backwards compatibility (and if you do, not all of the size class features are available anyway). I just made a new version of the app that only supports iOS 8, since users on older versions will just get the previous version of the app.
Resizable images: you can now specify resizable areas within images in order to control how they get stretched when applied to things like UIButtons, etc, that may change size according to Autolayout rules. (This is a feature Android has had for quite a while, so it's welcome on iOS.) This means that you can make things look good on a wider variety of screen sizes without having as many separate images or as much precise control over the size of the UI elements.
Programmatic code in the view controllers to tweak anything that you can't achieve any other way.
While it's true that you don't have quite as fined grained control over which devices show what exact layout with size classes, I found that this wasn't really as big a problem as you might think, as the size classes let your view controllers adapt to different devices very seamlessly. The combination of autolayout and size classes is particularly powerful. And it's actually potentially a good thing, because it means less new manual configuration whenever Apple comes out with a different screen size. It's a bit of a pain right now to convert, but probably worth it in the long run. You just have to think about how you set things up a little bit differently. It is a little bit more like Android, where they have long had to contend with lots of different device screen sizes and resolutions, but it's also the sort of natural evolution of the platform where you can't really precisely design for every single physical device as a practical matter (you should still test on them in the simulator, though).
Size classes are not there to just adapt to a larger screen size, they are there for completely different layouts. Like on an iPhone you might show one item and tap to get to the next screen for more information, but on an iPad you show both on the same screen.
For small adjustments, you use auto layout, with different layouts per size class, and the different screen sizes in each size class are handled by the auto layout.
I am new to iOS programming and programming in general so this will probably be a fairly easy question to answer for someone who is experienced.
I am making a game using sprite kit and I need to include different background image sizes for the different retina display sizes on the iPhone 4 and 5. I am using a graphics package to create the images in .png format then adding them into the project, the issue I have is that, if I make a 640x1136 size image, it works on the 5, and if I use a 640x960, it works fine on the 4 but leaves blank space around the edge on the 5. (I am running it on the simulator)
If I include two identical images with different names, one for each device, how can I load the right one in? Do I only need high resolution image and can use some code to change how it loads the image in, so that it covers the whole screen without pixelation or loss of quality on both devices?
Any help or advice is appreciated. I apologise if this is a simple question, thanks for your time.
Note:
I found out plenty on the internet about using the #2x suffix for high resolution images, but that's not what I'm looking for. I know how to code for different resolutions, just not two different screen sizes with the same resolution, if that makes any sense.
If you're on iOS 7 SDK which you most likely are, make use of the .xcassets catalogue. It has options for different screen sizes, put the different versions of your image there. And then load image in code.
The BB OS 5.0 supports images for context menus. The API documentation says the image will be scaled to fit a square set by the height of the menu font. I find that totally unhelpful.
The only way I can explain that method of calculation is due to screen resolution and DPI. But since the 5.0 OS is only valid on a handful of devices with similar screen sizes, I reckon they can specify the actual icon size they use.
I'd like to choose an icon size that's closest to the default menu font height so that the they look OK.
What size do you use? Do you even use this feature?
I haven't used it yet, but I would recommend using any square ratio maybe up to 64x64; the problem is that with new devices on the horizon (eg rumored tablet - with much bigger display) it won't necessarily be practical to target a specific screen size.