Auto Adjustment of UIImageView - ios

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.

Related

Resize UICollectionViewCell to fit image

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

UIButton dynamic font size

The image shows a 3x3 grid which is a vertical stackview, which contains 3 horizontal stackviews, which contain 3 buttons each. The top horizontal stackview has a correctly sized set of numbers within it(just by setting the font size to 80). The other two do not.
I want the numbers to take up the same amount of space on all devices so every number on each button is the same relative size on every device. This must be done programmatically! Not in IB... I cant find much info on this topic so even a link would be helpful please.

iOS when one views height increase with code , alignment is deteriorating

I am trying raise the height of the ranked successive views. There is a certain distance between each of these views.(Vertical spaces)When I increase the height of one of them, distorted distance between the bottom. I can not align all elements under one single at a time. This event is automatically done on Android. How do I make this operation on iOS.
That is the problem

Image position between inputs xcode 6

Good afternoon,
I'm trying to put an image in the middle of two inputs, that means that I would like to have the same margin to the first input as the second input. I'm going to explain better with an example:
[input a]---- 20px-----[image]---- 20px-----[input b]
I want to have the image always at the middle between them, because when I rotate the screen I have to make it large.
I have to use constraints? Which one? Is it possible?
Thanks in advance.
There are a number of ways to approach this. (There are a number of ways to approach everything, lol).
I'm only going to show AutoLayout solutions because it will make things easer when things are moving. Also, your description is pretty much already using AutoLayout Visual Format Language.
The first would be to place inputA, inputB and image into a third view which I'll call interfaceView.
Now you can lay it out like this...
|[inputA] // i.e. up against the left edge
[inputB]| // i.e. up against the right edge
[image] is different. You then align the centre of image with the centerX of interfaceView
The second option is to use "spacer" views.
Create two more views called spacer1 and spacer2 and layout the screen like this...
[inputA][spacer1][image][spacer2(==spacer1)][inputB]
Make spacer 1 and 2 hidden. They are just there for layout purposes. Now, because I have given them equal widths they will align the image view exactly in the middle of A and B.

Using metafizzy isotope to create a custom center alignment of items in rows, is this possible?

I have a design with a custom layout for a lot of images which looks simple but development wise isn't. What I want to do is use Isotope to align and filter all of the images, but the alignment is custom. The images should always center within their container and the maximum number of items in a row alternates, so it goes Row 1 has maximum of 3 images, Row 2 has a maximum of 2 images, repeat this order for all other rows. I included a link to a quick diagram of how this will play out with different amounts of images. I'm not sure how or if Isotope can center these images no matter what the total number of them is per row. Any thoughts on this one?
No, for something like this, you better look into algorithms related to circle packing and bin packing. You find good algorithms via MATLAB and Mathematica.

Resources