StretchableImageWithLeftCapWidth stretching wrong portions - iphone

I am trying to use a UIImage with stretchableImageWithLeftCapWidth to set the image in my UIImageView but am encountering a strange scaling bug. Basically picture my image as an oval that is 31 pixels wide. The left and right 15 pixels are the caps and the middle single pixel is the scaled portion.
This works fine if I set the left cap to 15. However, if I set it to, say, 4. I would expect to get a 'center' portion that is a bit curved as it spans the center while the ends are a little pinched.
What I get is the left cap seemingly correct, followed by a long middle portion that is as if I scaled the single pixel at pixel 5, then a portion at the right of the image where it expands and closes over a width about twice the width of the original image. The resulting image is like a thermometer bulb.
Has anyone seen odd behavior like this and might know what's going on?

Your observation is correct, Joey. StretchableImageWithLeftCapWidth does NOT expand the whole center of the image as you would expect. It only expands the pixel column just right of the left cap and the pixel row just below the top cap!
Use UIView's contentStretch property instead, and your problem will be solved. Another advantage to this is that contentStretch can also shrink a graphic properly, whereas stretchableImageWithLeftCapWidth only works when making the graphic larger.

Not sure if I got you right, but LeftCapWidth etc is made for rounded corners, with everything in the rectangle within the rounding radius is stretched to fit the space between the 'caps' on the destination button or such.
So if your oval is taller or wider than 4 x 2 = 8, whatever is in the middle rectangle will be stretched. And yours is, so it would at least look at bit ugly! But if it's not even symmetrical, something has affected the stretch. Maybe something to do with origin or frame, or when it's set, or maybe it's set twice, or you have two different stretched images on top of each other giving the thermometer look.
I once created two identical buttons in the same place, using the same retained object - of course throwing away the previous button. Then I wondered why the heck the button didn't disappear when I set alpha to 0... But it did, it's just that there was a 'dead' identical button beneath it :)

Related

Reduce Fill Image from Two Sides

I have set Image Type to Filled because I want to reduce the size of my filling area.
On the left side, you can see my progress bar within the attached image.
Within the inspector, you can clearly see I have set Fill Origin from Top so image size gets reduced from the bottom.
Now one twist I want, I want to reduce an image from both sides top and bottom, I have already played with Image component different values but I can't able to get success.
Overall I want to reduce the size of the image from the top and bottom.
There are 2 ways you can achieve this effect:
You can instead change the Y scale of the image, whilst the Y pivot is 0.5 this will make it shrink from top to bottom, but this will only work if the sprite looks the same even if shrunk down.
If your sprite's shape won't allow for changing the scale like that, you could also split it into 2 sprites at the midpoint and put them next to each other, and then have the top side fill from bottom, and the bottom side fill from top.

Resizing command changes image shape

I have to resize image i.e if its dimension is 3456x5184 to 700X700 as my code needs image with less number of pixels otherwise it takes too much time to give results.So, when I use imresize command it changes the dimensions of image but at the same time it changes the shape of image i.e the circle in image which I also need to detect looks like oval instead of being cirle. I need your suggestions to resolve this problem. I am really grateful to you people.
Resizing images is done by either subsampling (to get smaller images) or some kind of interpolation (to get larger images)
Input is either a factor or a final dimension for width and height.
The only way to fit a rectangle into a square by simply resizing it is to use different scales for width and height. Which of course will yield in a distorted image.
To achieve what you want you can either crop a 700x700 region from your image or resize image using the same factor for with and height. Then you can fit the larger dimension into 700 and fill the rest around the other dimension with black or whatever you prefer.

Hide UI/Image partially in Unity 5

Does Unity 5 support partial hiding of a UI/Image?
For example, the UI/Image I have in my scene has 100 width and 100 height.
At time = 0, the UI/Image is hidden. When time = 5, the UI/Image only shows the first 50 pixels. When time = 10, the UI/Image is fully drawn.
The answer to the question is in this link
Set the image type to Filled
Set the fill method to horizontal
Set the fill origin to left
From the script, update the fill amount from 0 to 1 over the timespan
On first thought, I can come up with two workarounds for this.
If the background of the image-in-question is a solid color, you can use another image with the same color as background that covers the actual image, so that it looks like the actual image is partially revealed. Then, just reduce the length of this covering image over time to achieve a revealing effect using Coroutines.
You make multiple image files with alpha channels and change the textures of the UI/Image over time. Each image will act like an iteration of revealing effect. Say you have 11 images, the 6th image will have first half revealed, and second half as alpha=0. In this case, if you want smoothness, you will need a higher number of images.

Two textures scale difrrent on retina iPad

I'm having a problem with that code:
rect = new Rect(saveTextures[0].width, saveTextures[0].height, saveTextures[1].width, saveTextures[1].height);
GUI.DrawTexture(rect, saveTextures[0]);
if(GUI.Button(rect, saveTextures[1]){
//do stuff
}
It should look exactly the same, and it does in editor. It also looks totaly the same on iPad2, but on iPad3 the top GUI.Button is scaled down to approximatly 90%.
Any ideas what could be the problem?
I make a simple example of the problem. Here is how it should look and looks on iPad2.
And here is how it looks on retina screen:
The red part is the button, and it covers whole background on first but only like 90% on second.
Make sure you set the texture type to GUI and that its max size is high enough (try 4096 if not sure).
Also noticed that your Rect constructor is a bit strange. It's new Rect(top, left, width, height), so you're using saveTextures[0] as top-left and saveTextures[1] as width-height while displaying them in the same position.

UILabel animated resize side effect

I came across issue where I need to animate height change of UILabel frame or its enclosing view's frame. Label is multiline.
The issue is that given with large text which does not fit initially into label(say it takes 3 lines), then animating the label's height to increase, immediately changing 3 line to 4 and then animating the frame increase.
Opposite effect is when the text fully fit into label(4 lines), then I animate height decrease, 4 lines are instantly becoming 3 and only then I see animating frame size decrease.
This is of course not good for an eye.
What I expect is something like keep the label's origin.y intact and then as frame is increasing the more text is revealing from the bottom. The ellipsis may convert to missing word instantly, that is not a problem.
If you want to keep origin.y intact then you have to animate it with CoreAnimation stuff.
Set once:
label.layer.anchorPoint = CGPointMake(0,0); //I believe 0,0 is the upper left or it was 0,1?
after doing this you just need to change the size accordinly:
I would measure the text first (With NSString's methods)and see if the label needs to be resized.
In case it needs to then adjust label.numberOfLines and label.layer.bounds = CGRectMake(label.layer.bounds.origin.x,label.layer.bounds.origin.y,
label.layer.size.width, newHeight);
This should work
I hope this helps.