Fixed Button Position Relative to ImageView in Xcode - ios

In my project I would like to essentially 'Pin' a button to a certain position on an image. The imageView scales to the screen size from the centre and maintains its aspect ratio.
I am trying to make it so that each button remains over the chakras "coloured icons in centre of body". I need them to maintain a scale that is the size of the chakras and maintain their position over the chakras regardless of screen size.
Wanted Result
Current Result
Scaling Settings
Aspect Settings

Here's an example - you will want to play with the exact positioning, but this should show you the method. You can do everything using auto layout in Xcode.
I took one of your images, and edited it to remove the buttons, and used it as the image in a UIImageView filling the screen of a UIViewController
Then I created 7 small buttons, and added constraints to them width & height = 20, and Align Centre Y to Image View
The tricky part is to add a constraint to align the centre of each button to a fixed percentage of the UIImageView centre - and that will be trial and error until it looks right.
Here's how to set the constraint
here's the app running on the iPhone 12 simulator
and here it is on an iPad (12.9 inch)
and here in landscape

You can take parent containerView for each imageView and Button.
Please see the picture to this link for better understand.
https://ibb.co/dsTjxbw

Related

LaunchScreen.storyboard appearing differently on devices than in Xcode?

I am attempting to customize the default LaunchScreen.storyboard of my Flutter app. I simply have a red background on the default View, and I added an Image View as a child of it. This Image View is centered on the screen and renders an image that I have added to "Assets.xcassets" with all 3 sizes. Below is a preview of what my Xcode displays:
However, this storyboard renders differently on devices than it appears in Xcode. For example, it appears slightly off-centered on iPhone 12, and it is scaled up too high for iPhone 6s and is way off-centered. See below for screenshots:
As you can see, the storyboard renders differently on the two devices. How can I make the storyboard appear the same on both devices as it does in Xcode? Any help is appreciated. If I used any incorrect terminology or need to provide additional details, please let me know as I have minimal experience using Xcode.
From the storyboard screenshot attached, it looks like there are no constraints added to the UIImageView.
You should add top, leading, bottom & trailing constraints to superview with 0 spacing to achieve what you want.
UPDATE
Above is applicable to the case when you have a small size image like 100x100 or similar that can easily fit on all screen sizes. In the comments, we see that image is way too big and we want to keep it in center while occupying 50% of screen width.
Remove the leading and trailing constraints, select the imageView and it's superview - add equal widths constraint with a multiplier of 0.5, this will make sure that imageView will always occupy 50% of the superview's width.
Also add horizontally center constraint on the imageView. Make sure imageView Content Mode is set to Aspect Fit.

How to center image horizontal for all screen size in xamarin ios native

I want to center image horizontally.
Here is my activity :
As above you can my storyboard. There are two images. 1st Image in background which cover whole screen and that's perfect for all devices. Now i have other image which you can see horizontally center and its work fine with iphone 6s plus. But when i have checked with iphone5 and X this image its not in horizontal center.
I have used auto layout .
Here is the constraints:
How to set this image horizontal center for all screen size ? and also how can i give padding top same for all device screens size ?
Refer to Center Constraints
Drag the square handle to the vertical Center green line of superView,as illustrated by the screenshot below
I center image in this way:
And as I look is easier to make storyboard in Xcode and then copy to xamarin project.
--EDIT--
In your storyboard add image on center of view and click on image and then in the Constraint Edit Mode:
Next on the center of image you will have pin spacing
And move this pin to the horizontal and vertical line. All the time look at the properties Constraints
Then you need to add spacing with one of the side. I add on the right:
After this you need to set value of space. I use 10
After all of this steps i have this constraints:
Sometimes I have to uninstall and install again app on simulator or phone to see changes.
here is very simple solution
use frame mode
use arrange as in the image. choose all arrows on the left panel
Thus your image will be always in the center and resized for the device if you provide 3 sizes of images.

How to make iOS ImageView full match window?

I am new in iOS , I am an android developer self-learing iOS just for fun.
As you can see from the picture , I want to make my ImageView full-displayed in the window in different inch iPhone.
If you are an android developer, you may know what I mean is how to make ImageView match_parent in both width and height?
You must set the UIImageView Constraints, like this to adjust in the full screen, 0 spacing in all sizes, and click in Add 4 Constraints
After that, you must check in the UIImageView settings the mode to Aspect Fit, so it will keep the aspect ratio of your image.
I Took the image from your print, here is the expected final result.
Pin the image view on all four sides to its superview via constraints with a constant of zero. Now configure the image view's content mode so that it doesn't distort the image, but rather keeps its aspect ratio (there are two ways to do this, and I don't know what one you want, so you will have to experiment).

Adjusting Y position of Elements for all Iphone screen size using AutoLayout

I am using an Image view which is placed on top of parent view. Color of parent viewis changed. i want my design to look same on all iphone sceen sizes in portait. top tabel is positioned accuratly as it should be in the center. but I am having issue with my Logo as you can see in screen shots Logo is at perfect place in only iphone 5.5 inch. what constraint i should set to position my logo as same point (lets say S in "YAS" should be touhcing the hair of girl as in Iphone 5.5) for all devices ?
i have applied constaints but its not working please guide me
This is wahtI am getting in previw
These are my Constraints
This is my Xib
I tried differecnt values for multiplier but nothing happened
image View is in Scale to fill mode
Position your LOGO Horizontallycenter manually and then give TOP , LEADING , TRAILING and aspect ration constraint . When your view's width will increase these constraints will increase height of your Logo.
Also set your ImageView(Logo) View -> Mode to Bottom (in Attribute Inspector).

UIImageView sizing in AutoLayout + Size classes for all devices

I'm working on app and will for 1st time use auto layout/size classes. Today my first day learning it and I understand constraints now and how to place the images where I want them to be on every devices from iPhone 4s to iPad PRO.
As my main storyboard in Attributes inspector i'm using INFERRED size. In show Assistant Editor, Preview, i'm using all device sizes.
In my inferred storyboard i'm using a UIImageView size 170 Width, 230 Height. Then I use AutoLayout to make it center of every device screen in preview.
Now the issue is this UIImageView covers HALF of the size of iPhone 4s preview but only about 1/5th the size of iPad PRO. How do I alter the size of each UIImageView to the size that I want them to be in each device without changing that centered position of each UIImageView in the preview devices?
You need to first set up your constraints properly and then choose the type of scaling you want.
Set up your constraints:
Click on the Pin icon |-[]-| at the bottom of the screen. Turn on all four orange I-beams. Set the four constants to zero.
Uncheck the Constrain to margins checkbox and click 'add 4 constraints'
Then set your scaling:
Click on the Image View you added to your View Controller.
In the Attributes Inspector on the right, choose your image.
Set the Mode of the View to Aspect Fill (fill entire screen cropping top/bottom or left/right as necessary) or Aspect Fit (letter box image so that entire image is shown uncrossed).
That should work
Maybe you can use a pending or proportion constraints instead of width and height constraints.

Resources