How to change the position of a label based on how big an image is - xcode

My image changes size and I want to know how to keep a label in the same spot on the image no matter the size. I want to keep the label inside of a speech bubble, is there a way to put constraints on it to do this, or is there another way? I'm working in Xcode.

Instead of giving constant position values, derive the required position using height and width of the image using mathematical calculation.
Example:
Let's say the image size is 400x400 and you want a label at bottom right
You can derive it as
X=width-width*0.75
Y=height-height*0.8
Now even if the height and width varies, the label will be in same location

Related

How to crop a photo in a storyboard (Xcode)

I have an image that is part of a vertical stack view (which includes a label and button), and there is a lot of blank space around the image. I was wondering if there was a way to get rid of this empty space so that the label and button are much closer to the actual image. Thank you!
You need to set an Aspect Ratio constraint. Like so:
Set the aspect ratio to 1:1 to get a square. This will prevent your circle image view from expanding to a rectangle.

Image sprite slide on hover - responsive?

I want to show another image on hover and due to the layout of the homepage I need to use sprite to do it. I've got it working fine, but I'm using fixed width and height for the container.
You can see my JSFiddle here:
http://jsfiddle.net/mckeene/fhk0byqt/4/
The problem arises when I want to make it responsive. I can use max-width: 100%, but what about the height?
OK, this solution is based on the known fact that some properties like padding-top and margin-top, when given values in percentage, are calculated based on the width of an element rather than its height.
Making an element “as high” as required by the known dimensions of a responsive image can be done by using padding-top – I used a value of 66.54% here based on your image’s dimensions (half the image height divided by the width, times 100) to span the container element up to the required height.
Now normally to display the upper half of an image first, and then the second half on hover, I would use absolute positioning – but we can’t use top here, since a value in percentage for that property would be based on the height. But luckily, as already mentioned, margin-top is one of those properties where percentage is calculated based on the width – so we can use margin-top: -66.54% here to “pull” the image up over its container’s padding first to show its upper half, and then double that (margin-top: -133.1%) to pull it up even further on hover, to show its lower half.

How to set x,y coordinates of elements in xaml pages

I've been trying to move an image by setting its margin but that only changes it size. I want to move an image by changing its x coordinate. How can I do that(in xaml, pages and not wpf)?
You're image may have it's Stretch set to fill the available space. When you change the margin that could give the image more space so the image expands to fit. If you set the StretchMode to None you may see the margin will affect the position instead.

Flex Mobile GetPixel function of a resized image gets pixel as if the image had its original size

I have an image of 780x585. I am resizing this image to 1246.93x935.19 with scaleMode=ScaleMode.LETTERBOX.
When the user clicks on a graphic and drags it into the picture, I am supposed to get the pixel position where the graphic was dropped.
I do that by listening to the mouse up event and by calling getPixel with the (x,y) coordinates coming from the event when the mouse click is released.
Strange thing is that I get the value of the pixel but not the real one. Instead, I get the value corresponding to the image with it's normal size without being resized.
Does anyone have a clue why this is happening?
Thanks,
Dave
When applying some visual changes to a component (like moving, rotating or stretching as in here), Flex will be applying a transormation matrix to modify only the visual appearance of the object.
Let's say you're moving an image by doing image.width *= 2; the actual image width will be modified. If you do image.matrix.scale(2, 1); (this is pseudo-code), the visual appearance will be modified so you can see the resizing but the the actual width will remain the same.
I think applying a Letterbox resizing is using matrix transformation, so even if your image appears larger, its position and size are still the same. That's why you get the same position as before.
To resolve your problem, you simply have to multiply the coordinates you get (with event.localX or anything else) by the image current scaling and that should be it.
If you already know the final size, you simply have to do something like: newLocalX = event.localX * (resizedImage.width / originalImage.width);
Here some info if you want to know how Matrixes work.

how to calculate the right resolution for an image overlay in openlayers

I have an image I use as overlay in a vector layer in my openlayer web application. The idea is the same as showed in this example
What I do not understand is how to set a valid resolution to my image so that every time the user changes the zoom of the map, the image width and height is adjusted to cover its real geographical area.
In the example above some images are used and placed at some specific locations using a specific and hard-coded resolution factor.
Assume I have an image 400x400 pixel which represents an area of 400x400 kilometers, I need to recalculate the width and height of my image every time the zoom factor changes using a formula like this:
imageWidth = imageWidthInPixel * theResolution / map.getResolution();
imageHeight = imageHeightInPixel * theResolution / map.getResolution();
where 'theResolution' is the value I need to calculate some way I don't know. I guess this is a value that depends on the area expressed in kilometers or meters the image covers, but I am not able to find out a relation that has a sense. As explained above, in the example I reported, these values are hard-coded and depends on the image but there is no way to understand how these values are calculated.
Please help me understand this.
If you know the projection of your image, it would be easiest to simply define the image as a layer defined in OpenLayers with the appropriate projection. At that point, OpenLayers will handle the zooming and panning for you.

Resources