Im using a library called JTAppleCalendar and it uses a CollectionView to draw out the Calendar. I want that my Cells have small lines separating them so i set the calendarView.minimumLineSpacing to 0,4 but what i get is a mismatch of lines (some are thicker than they should be) see in picture
My goal is to get equal lines. The width of the Calendar is the device width (in my example 375 (iPhone 12 mini)) and the height is fixed at 295.
I have researched a lot and, found out that this is some kind of UIKit problem because the cell sizes are not an even number. ( maybe this issue is also useful )
Please help me solve this problem.
Related
I am currently working on UIImageView and I have an API which returns a number of images, maximum =5 and minimum=1, I have to adjust the position of the image based on the response.
Suppose I have five images
Restaurant
Parking
Outdoor pool
Interent
Bars
API can return 1 or 2 or 5, it varies.
I need to adjust the images accordingly like if 3 images than I have to show three and hide remaining two.
I have tried UIStackView but it didn't work as per my requirement and now I am working with Leading and Trailing constraints but it seems they don't work too.
I there any other workaround to achieve this?
Try using UICollectionView as number of images used here are dynamic is number.
I'd like to resize UICollectionViewCell to fit image that is sensibly resized and maintains dimensions/aspect ratio. If I simply set the size of cell to size of image it may be way too big. Also, If I run on different sized devices, the spacing isn't consistent. Must I implement collectionView programmatically to overcome this?
I see many apps that do this so its a very common problem that may already be solved as a framework.
Example:
UICollectionView is actually of arbitrary layout. It so happens that the default is UICollectionViewFlowLayout which is a grid, but you can change it to anything by implmenting your own instance of the UICollectionViewLayout protocol. Int the case you cited its pretty easy. The width of the cells is the collectionview (width minus the padding) divided by two. The height is the aspect ratio times the width + the spacing + the label height. all the cells with indices divisible by 2 go in the right column and the rest go in the left column. It should be easy to calculate these values for layoutAttributesForItem(at:). Unfortunately its a bit harder to calculate for collectionViewContentSize. Assuming your collectionview is sufficiently small I think its best to just precalculate all of the hieghts and use the cached values for these functions.
There're a lot of open sources on github You can refer to.
https://github.com/zhangsuya/SYStickHeaderWaterFall
The default row height fits four rows exactly into the 42mm Watch. But on the 38mm Watch, the fourth row is cut off.
In IB I have the generic "Installed" checked for the Table; for Images (e.g.) this leads to customizing sizes but I don't see any such option for Table row height. Or would I just use what looks like Watch Size Classes, clicking down at the bottom where it says "Any Screen Size"? If so, how would that interact with the "Installed" settings?
I am going to hack around, but some SmartPerson™ could help a lot by pointing in the right direction.
FWIW, all the Apple sample code I've seen has the "38mm cutoff" problem too.
Why the rows are cut off
The row heights are intentionally the same, for a couple of reasons.
While I don't see a minimum row height mentioned in the design guide, shorter rows would make it harder to target the right row on the 38mm screen. This would lead to an inconsistent user experience between the two watch sizes.
A shorter row would lead to the issue of vertically clipping two-line text, which would occur more often on the 38mm screen since the rows are narrower.
This example illustrates how the last row's WKInterfaceLabel text descender gets clipped by its group once you reduce the group height for a 38mm screen to fit 4 rows on the screen.
The shorter row also leads to an insufficient amount of (vertical) white space around the text, making it harder to read rows of content.
Consistent row heights are no different than how some iPhone models can fit more rows per screen compared to some of the smaller-screened devices. Apple doesn't modify the iOS row height to fit the same number of rows on the smaller screen, as could fit on the larger screen. Their watchOS sample code is really consistent with their general design philosophies.
How to accomplish what you ask
You can change the group's height from Default to Fixed, and specify a smaller height (of 34 points) for the 38mm device. This would fit 4 rows on the smaller screen, as illustrated by the previous screen shot:
You should adjust your content as necessary to preserve vertical white space between the content and its group container.
I have a UILabel in a collection view cell that is center aligned with number of lines = 0 and line breaks = word wrap
My text is dynamic, dependent upon requested data, so some cell's don't need two lines.
Any idea why it still wont go to the second line if needed? Getting stuck on this.
While I do not know because I do not see any code, I suggest looking at the size of the label. Are you sure the label is not getting stretched / set to a size larger then the collectionviewcell?
I think this is what you're experiencing:
I made two labels, each with:
number of lines = 0
word wrap activated
just enough x and y constraints to keep them in place on the view!
I think this is what you want:
I added constraints to each label making their width less than or equal to 300
I'm setting up a collection view and customizing its cell's width, inset, and inter-item spacing. With the current size that means there would be two columns in portrait and three in landscape. I let flow layout do the rotation adjustments & calculations, but the result is a stretched middle column. I think what is happening is flow layout is doing the math for the cell padding/spacing and not getting clean whole numbers. Then it adjusts the size of the actual cell by half a point. The result is an aliased & blurry looking cell.
I'm had this issue multiple times and each time - I manually calculate the values for each orientation to come out as a clean whole number. While this works, it doesn't seem very efficient. I'm wondering if there is a better way to do this, and if FlowLayout has the ability to say, give that half point to a margin or the empty space between the cells?