Adressing CLS (Google page speed) - cls

So im trying to address CLS on my webshop: www.jupiter.dk
It's a template with bootstrap, and responsive layout.
CLS requires me to have a set hight and width on all images. But if i do that, they are no longer responsive?

They don't need to be fixed values. For example, in CSS, you can say the width is 50% and provide an aspect-ratio to let the browser work out the height.
If your width matches how your responsive image does widths and the aspect ratio is correct, you will allocate the right space for the image and have no CLS.

Related

Content of Grid list to fill the height

I am placing content in the grid list component and I want the grid tile to grow accordingly to the content it has. I tried to use rowHeight="fit" as documentation states but it doesn't seems to work.
Here an example
MatGridList overall size is directly related to the rowHeight setting. The default rowHeight value is a ratio 1:1 (which means column width equals row height).
When you use a ratio, the list will have a fixed width/height ratio overall, so if the list can't grow in one direction because of window or layout restrictions, it can't grow in any direction. This is why your example looks the way it does. If you expand the width of the window, you'll see the list expand vertically as well. You can set a different rowHeight value to make the tiles taller than wide such as rowHeight="1:2" (that seems backwards to me but that's how it works).
When you use rowHeight="fit", this doesn't fit the list to the content, it fits the row heights to the list height, but as noted in the documentation, you must set a height on the list or a parent for this to work properly.
Setting a fixed value for rowHeight does what it sounds like.

Hugging/compression for UIViews without intrinsic content size?

I’ve been asked this question on a job interview and I’m wondering what he meant.
The role of hugging and compression properties for any view with intrinsic content size is obvious.
But what about views without intrinsic content size? Do they play a role there?
Kind of an odd question, without some additional context.
However, I suppose you could discuss a couple things...
Some views get an intrinsic content size after-the-fact. A UIImageView, for example... without an image, it has no intrinsic content size. But once you set its .image property, its intrinsic content size will be the size of the image. So, you may want to set the priorities based on what will happen.
You can give a UIView, for example, "Placeholder" intrinsic content size. Changing the hugging/compression priorities will affect that view during design-time.
In both of those cases, you would be "planning ahead" during Storyboard / IB design for what you want at run-time.
EDIT
Here is a (rather long) example:
Here I have a UIView (green) containing a UIStackView set to Fill / Fill / 8. The stack view holds a UIImageView (Scale To Fill) and a UILabel. The image view has NO intrinsic content size, while the label has an intrinsic content size, based on its content.
With the constraints I've set, the stack view is 200 x 240 points.
At run-time, I'm going to set the image to a 200 x 100 png of a cat:
My goal is for the image view to "fit to the image," letting the label expand vertically.
When I set the .image via code (at run-time), the image view "gets" an intrinsic content size (of 200 x 100 in this case). With both the image view and the label having Vertical Content Hugging: 251 (the default), this is the result:
But I want the image to retain its original aspect ratio of 2:1. First thought is to change the image view's Content Mode to Aspect Fit -- but I get this result:
Now my image view is "letter-boxing" the image, showing the red background color.
So, I change the image view's Vertical Content Hugging: 252 (higher priority than the label). The output:
Now I have the run-time output that I want, but at design-time (working in Storyboard / IB), nothing has changed and it may not really be clear what's going to happen.
So, I give the image view a Placeholder intrinsic content size of 200 x 100, and I see this:
Because it's a placeholder, that will have no effect on the run-time output (if I set the image to a 200 x 50 image it will be 200 x 50 at run-time), but it better reflects what I'm expecting.
Of course, there are other ways to accomplish the goal, and this may not be the ideal approach, but it (hopefully) gives an idea of one way that setting Hugging / Compression priorities on elements with no intrinsic content size can be useful / needed.

how to make the label proportional to the screen size?

I am a beginner, I am trying to do an autolayout. I am trying to make the label 'HRIS' and 'Please login to continue' to be proportional to the screensize (its superview), I can do it for the login button and the image leaf as the picture above, we can see that the login button and leaf image are proportional.
for the image leaf, I do equal width with 0,1 multiplier to the superview, and then I also add 'aspect ratio' to make it proportional.
but when I apply the same way to the label, it doesn't work, as we can see the label size still the same for iphone 4s and iphone 8, maybe it is because the instrinsict content size (the font size itself) that makes it like that. I tried to apply this way, but it seems the size is still the same
I want to make it little bit smaller for iphone 4s, I also can't modify using size classes since it is in the same class
so what I have to do to make label proportional to the superview (screen size / background) ?
You can do it by setting both proportional width of the label and allow it to scale down the point size.
Set the label width to proportional width like this. It is just a regular same width constraint that you edit.
Then allow your label to scale down the point size like this. This is a property of your label.
Set different font size using variations...
Simply set up a constraint for your label's width to be equal the view's width with your desired multiplier. In my example I used a multiplier of 0.5:

Set numeric UILabel for Auto Layout to correctly compute the intrinsic content size

I have a UILabel with a font of size 50 and text 1. At runtime, its text is changed to other numbers.
If I, say, center it in its superview, the automatically detected (intrinsic content size) height is a lot bigger than the actual text, and this is because it tries not to crop other lower characters like g.
The thing is that I know I won't use other characters than digits. I also don't want to set a fixed height constraint for it.
UIFont metrics include ascender, descender, cap height, x height, etc... all of which determines how the characters fit into a container. There is a good explanation and diagram here: http://cocoanetics.com/2010/02/understanding-uifont
If you really want to get the height (and/or width) of the individual character "glyphs" you'll need to use Core Text. This will include calling CTFontGetGlyphsForCharacters() and CTFontCreatePathForGlyph() to get the "glyph path" (a CGPath object), at which point you can get the "bounding box" to determine the exact size.
Lots of discussions and example code out there... A good starting point is simply searching for CTFontCreatePathForGlyph

What is the "Adjustment" preference in WatchKit-Storyboard for?

I couldn't really find anything on the web yet, what the Adjustment preference on WatchKit's UI elements does.
Does somebody know?
The adjustment will add or subtract that many points from the size of the element. Say you have an element who's height is set relative to the container at 50% and then you add an adjustment of 10. If the containers height is 100 then that element's height will be 60 since it will be 50% of 100 plus 10. I am using it in my app to get the exact height that I want relative to the height of the watch.

Resources