How to crop a photo in a storyboard (Xcode) - 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.

Related

Xcode Image Slicing Not Working with Gradients?

I have PNG images with rounded corners, inner shadows and a fill gradient, that I thought I could slice in Asset Catalogs horizontal and vertically. But no matter what I try, the gradient slice doesn't stretch or tile as I expected. With Xcode 9.1.
The gradient is not copied (although the inner shadow is), and in IB and the simulator, there are just two bars and no gradient.
What am I missing?
Here are the original image:
Here's how I sliced them:
And what they looked like in IB:
And here's what it looks like in IB (with the colors reversed in the simulator (with a red view and another similar image as background without any gradient) and device.
The center is the part that is getting tiled. You defined a 1x1 square that’s getting repeated on the interior of your image in order to make the image fill the space you defined, which isn’t your stated goal. What you can do is change your center to Stretches, and increase the center’s height and width to take up everything in your image that doesn’t include your rounded corners end caps.

iText - Image border width changes based upon image

I'm adding borders to various images in a .pdf document. The borders all have the same width, but in the .pdf the borders have different widths. It is more pronounced as the width of the border increases.
Also, is there a way to move the border outside of the image, so that it is not covering any of the image using the methods of the image class? I realize I can first put a filled rectangle and then add the image on top of the rectangle as an option. Just curious as to if this can be done with methods from the Image class.
Here is the code snippet
magazine.open();
canvas = pdfw.getDirectContent();
image = Image.getInstance("a.JPG");
image.setBorder(Rectangle.BOX);
image.scaleAbsolute(200,200);
image.setBorderWidth(50);
image.setAbsolutePosition(50,10);
//canvas.addImage(image);
magazine.add(image);
image = Image.getInstance("b.jpg");
image.setBorder(Rectangle.BOX);
image.scaleAbsolute(200,200);
image.setBorderWidth(50);
image.setAbsolutePosition(50,230);
//canvas.addImage(image);
magazine.add(image);
I fear you'll have to work with the workaround you described.
There are two ways to define a border for an image:
image.setUseVariableBorders(false);
This is the default. This is what you have (even though you aren't calling the method explicitly).
In this case, the thickness of the border is distributed in a way that half of the line width is inside the rectangle and half of the line width is outside of the rectangle. Maybe that's what's causing the effect that the difference you notice is more pronounced as the border width increases.
Then there is:
image.setUseVariableBorders(true);
Now the borders will be drawn inside the area needed for the image. This is useful for tables (both PdfPCell and Image are subclasses of the Rectangle class where these methods are defined), but I fear it doesn't help you in the case of images.
So your best chance is to add the border using a workaround.

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

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

Image map re-sizing

I have been looking to dynamically scale a image map with coordinates to a div, so when re-sizing a window occurs the map and all coordinates are scaled accordingly.
any suggestions on how to do this?
i think this may work
http://blog.outsharked.com/p/image-map-resizer.html
but with the alternate option of :enter a bounding area and the map will be clipped to within that area.
my question then is how do i establish a bounding area, will it scale dynamically to that whole area?
This jQuery plugin works great for scaling and rescaling image maps on the fly. You can call this once, and it will take care of all image maps on the page. It will even rescale an image map if something happens that changes an image's dimensions.
https://github.com/stowball/jQuery-rwdImageMaps.
If you weren't just using the div to solve the image map scaling problem, you could put a blank image (a completely transparent .gif or .png) in your div with the image map applied to it and set its width and height to 100%.

How do I make a textview auto aline to textview?

How can I have a textview auto-align to an image?
What I mean is, when I change an image from a square to a triangle, how do I make the textview fit inside that triangle automatically?
Check out my "Quick Notes!!" app on the app store for reference. I am using Xcode 4.3.
Chances are you're going to have to do a bit of work to do what you want. I'm guessing you have a background image that changes from a square to a triangle and you want the textbox to remain inside of the shape. Since the imageview hosting the picture is still a rectangular shape the imageview dimensions don't actually change so you'd have to calculate or know the size of your triangle and scale the text box programatically based on a flag of whether or not you are displaying the triangle.
EDIT: Actually this is much simpler than i thought initially. Just position the textbox where you want it with what size in the .xib file and record the position and size. Then you simply check when you are displaying your triangle image and change the position and size of your textbox to what you had previously recorded.

Resources