How to subtract a view in iOS? - ios

For example I have a view, which is 320 * 320, black color, and alpha channel is 0.5.
I would like to open a view with position 100*100 , and width and height as 50*50. That's allow me to not apply the, black color, alpha channel 0.5 is that area.
How can I do that? Thanks.

The easier way of doing something like this would be to just use something like Photoshop to create the 320x320 image, and then remove the 50x50 window wherever you wan it. Make sure you save it as a png, and you will be good to go. No point in making things too complicated. Now if this image needs to change, it is more complicated, but that was not described in the problem.

Related

Set Pixelratio in Gimp to 0.5mm x 0.75mm

I have to paint some pictures for a small display of a micro controller. The Display has a resolution of 128x64 Pixel. But the Pixel aren't a square. They have a width of 0.5 mm and a height of 0.75mm. All my nice drawn images in GIMP look ugly on this display.
Can i change the ratio of drawn pixel in GIMP so i can see the image the same way like on my micro controller screen? Is there a setting for this or do i need to use my imagination?
I've looked around in settings menu but found nothing ...
thx in advanced
PS: Wrong Network?
Use Image>Print size to set a different definition for the vertical and horizontal axis (don't forget to "unlink" the two entry fields otherwise changing one will change the other).
Then untick View>Dot for dot so that Gimp no longer maps image pixels to screen pixels and displays the images with their intended definition (and aspect ratio in your case).

Position an UIImageView over another with scaling

Is there a method on UIImageView that tells me the position of its image within its bounds? Say I have an image of a car, like this:
This image is 600x243, and, where the rear wheel should be, there's a hole which is 118,144,74,74 (x,y,w,h).
I want to let the user see different rear wheel options, and I have a few wheel images to choose from (all square, so they are easily scaled to match the hole in the car).
I wanted to place the car image in a UIImageView whose size is arbitrary based on layout, and I wanted to see the whole car at the natural aspect ratio. So I set the image view's content mode to UIViewContentModeScaleAspectFit, and that worked great.
For example, here's the car in an imageView that is 267x200:
I think doing this scaled the image from w=600 to w=267, or, by a factor of 267/600=0.445, and (I think) that means that the height changed from 200 to 200*0.445=89. And I think it's true that the hole was scaled by that factor, too
But I want to add a UIImageView subview to show the wheel, this is where I get confused. I know the image size, I know the imageView size, and I know the hole frame in terms of the original image size. How do I get the hole frame after the image is scaled?
I've tried something like this:
determine the position of the car image in its UIImageView. That's something like:
float ratio=carImage.width/carImageView.frame.size.width; // 0.445
CGFloat yPos=(carImageView.frame.size.height-carImage.height)/2; // there should be a method for this?
determine the scaled frame of the hole:
CGFloat holeX = ratio*118;
CGFloat holeY = yPos + ratio*144;
CGFloat holeEdge = ratio*74;
CGRect holeRect = CGRectMake(holeX,holeY,holeEdge,holeEdge);
But there must be a better way. These calculations (if they are right) are only right for a car image view that is taller than the car. The code needs to be different if the image view is wider.
I think I can work out the logic for a wider view, but it still might be wrong. For example, that yPos calculation. Do the docs say that, for content mode = AspectFit, the image is centered inside the larger dimension? I don't see that any place.
Please tell me there's a better way, or, if not, is it proven that my idea here will work for arbitrary size images, image views, holes?
Thanks.
The easiest solution (by far) is to simply use the same sizes for both the car image and the wheel option images.
Just give the wheel options a transparent padding (easy to do in nearly every graphics editing program), and overlay them over the car with the same frame.
You may increase your asset sizes by a minuscule amount.. but it'll save you one hell of a headache trying to work out positions and sizings, especially as you're scaling the car image.

If I have images that always need to be cropped to a certain size before going into a UIImageView, is cropping the most performant?

This is heavily related to my question here: Is there a way to get a high-res YouTube video thumbnail without letter-boxing?
Say I always get images back from an API that need to be cropped. They always have black letter-boxing at the top and bottom.
Now I could programmatically crop every UIImage down to the size it should be, but actually altering the image seems like a very expensive operation, and a waste when I really just need to hide it.
How would I best go about putting it in a UIImageView and making sure that the black bars aren't visible? To make it easier, it's safe to assume that it will be cropped into an aspect ratio that is the same as what the image is without the black bars (so in the above example, 16:9).
Resample or Crop the image accordingly and then
YourImageview.contentMode = UIViewContentModeScaleAspectFit // or you can use UIViewContentModeScaleToFill;
then...
YourImageView.layer.maskstobounds = yes; // or YourImageView. clipToBounds = yes;

Xcode 5 Image Slicing

I'm trying to slice an image in assets Xcode 5. I don't know if what I'm trying to do is possible with slicing.
The image looks like this:
I need to change the width and the height of the image, although not at the same time. The closest I've got is when I use Horizontal for the height and Vertical for the width. The problem is when I change the width, the left side of the image starts as a straight line and the skews and change to the original shape.
I'm about to give up on the idea of slicing and just create three images, left, center and right. Is that the only way to go?
This is how my current slice looks like:
Is there any way to change it so it works at least for the width?
UPDATE
Instead of slicing the image I used a mask and moved the mask.
Slicing works by taking the center section, and stretching it to fill the required space and then putting on the image end caps.
Because your button has a continuous diagonal line you will not be able to slice it. It will stretch the image out like so:
In fact even if you make a centre section and end caps you will still have the same issue as this image can only be scaled.
If you only need a finite set of heights then you should create individual assets for each height that can be sliced horizontally. If you need N heights then you should look into using core graphics to draw your shape in code in a -drawRect: method for arbitrary dimensions.
P.S. if you want to horizontally slice so you can grow the width its most optimal to have only 1 pixel width of image that will be stretched out so your button image resources would look a bit like this:
Aha. TIL: You can change the slicing options from the attributes inspector in the right hand pane in Xcode. To make your slicing work choose only "Horizontal"

Stretchable UIImage chat bubbles

I have the following image attached that I use as the background of each of my chat messages (i.e. bubbles). What values should I use for X and Y in UIImage stretchableImageWithLeftCapWidth: X topCapHeight: Y]; to insure that the pointy end of the image stays in the middle at all times.
I tried using X=20 Y=5 but the pointy end goes to the bottom.
You can't do that with a single stretchable image. A stretchable image always has just one rectangular area that is stretched. To get the appearance you want however, you'd need to stretch two parts – the areas above and below the pointer.
You need to use at least two images. The easiest would probably be to make the pointer a separate image and center it manually on top of the rounded rectangle.
You can't do that and keep the arrow in the center -- well, not in iOS 6 and earlier ;-)
This is why the little speech arrow in Messages.app is at the bottom corner of the speech bubbles. They stretch an area of pixels that is just above that region.
So, you could make things easier for yourself by following Messages.app's lead and design around the limitation.

Resources