Stretchable image in drawRect causes slow scrolling - iphone

I am subclassing a UITableViewCell and in the drawRect: method I want to draw a stretchable image but I have experienced that this has a big impact on the scroll performance.
Does anyone know how I can use a stretchable image and still have a good scroll performance? Alternatively, I could make five images and draw those instead. One for each corner and a center image which would be stretched. This just seems such a hassle, and I actually thought that's what a stretchable image would do.
EDIT: If I should split up the image and stretch it myself, it should of course be nine images, not four. One for each corner, one for top middle, bottom middle, left middle, right middle and one for the center.

Try using [UIImage resizableImageWithCapInsets:] to create a resizable image instead of your own code. Create an UIImageView with image and just add it as subview to cell.contentView at index 0

Related

Display UIImageView image over it's parent UIImageView

I have an easy task but still don't get how to make it work.
I have a UIView, inside the UIView i have the main UIImageView of half UIView size (half display).
And inside of the UIImageView i have two UIImageViews with images.
I need to pan the internal UIImageViews, and that's not a problem but the problem is that it will not go above the parent UIImageView borders. Same happens when i use two UIImage instead of UIImageView.
I have tried to bring it on top (bringSubviewToFront) but it does not help because its parent controller not the UIView. And the two internal UIImageViews must be a part of the main UIImageView because the main UIImageView can move, so i move all together.
Any help appreciated.
Although the correct solution is to have a superview that's the correct size, you can always "see" what lies outside of the bounds by setting clipsToBounds to NO on the parent UIImageView.
This will draw the subviews even if they lie outside the bounds of the superview. Keep in mind though, that the parts that are outside the bounds will not react to touches, i.e the hit box is always clipped.
You can have one parent view, containing large image and two smaller as siblings. Then you an control position of two images freely without attaching them to larger image.
Like this:
-Parent View (the largest, within which all images aare displayed)
- Large image
- small image
- small image
Now small images are free, and you can align them to large image whenever you want!

How do I blur whatever is behind a translucent UIImageView?

I have a translucent png image (made by turning down the opacity in Photoshop), and there's a UIImageView behind that translucent image. Is there any way to blur the parts of the UIImageView on the bottom that intersect with the UIImageView on top? Thanks!
Not aware of any code that will do that on its own, but you could 'fake it' by rendering the intersection of the views in a graphics context, then apply a blur effect to it. Then you could take the graphics context and insert a UIImageView with the resulting image in between the two views to simulate the effect. This method would not work very well if you have any sort of animation or otherwise changing the state of the images.
You may try setting alpha of the image to less than 1.

Animating UIImageView over a background image

I have a UIImageView that I have resized to fit a small ball. The current background is black color. I want to set the background as some image and then move the ball on top of that image. I tried to use another UIImageView but the background takes over the ball image and the ball is not visible. Any ideas!
In IB, are you sure you have the small UIImageView in on top of the larger one? Try deleting the smaller UIImageView from IB and re-adding it on top of the larger one. I noticed that it's hard to tell which UIView is on top in IB for some reason.
Posting as requested. Glad I could help!
I would suggest not using interface build and just doing it programatically, much more control that way.

iPhone animation with stretchable image

I got a UIView subclass that draws a UIImage as its background. The image is created using the stretchableImageWithLeftCapWidth:topCapHeight: method, it has round edges.
I also use an animation block inside of which I resize my view. I had hoped that during animation, the drawRect:method would get called sometimes, which would result in the background image getting drawn correctly.
Unfortunately, the animation seems to render the image and then just rescale it during the animation, which obviously makes the formerly round edges getting nastily stretched.
The only workaround I can imagine is put three separate UIImageViews (top cap, middle fill, bottom cap) above my original background image and then reposition the caps images and scaling the fill image. However, this seems quite complicated...
Is there any better way I can prevent this from happening?
EDIT: Found this. Sounds bad...
While digging through some Apple docs, I coincidentally found the solution to my problem. All you have to do is play with UIView's contentStretch parameter. It allows you to manually specify the area of your view that gets stretched during animation.

iPhone - Center UIImage in UIImageView

I have a UIImageView. I get a UIImage from a URL. The image displays in the UIImageView, but I can't get it to center correctly. The UIImage is 80 x 68 pixels. The UIImaveView's size is 90 x 90. When I display the UIImage in the UIImageView the UIImage is shrunken so that it fits, although it is already smaller than the UIImageView. I have tried all the Content Modes in IB. Some of them shift the image up so that it is no longer in the UIImageView. None of this really makes sense to me. It seems that the UIImage should display inside the UIImageView fine if it is already within the required size. Any help would be great.
With Mode of Center on the UIImageView
alt text http://img406.imageshack.us/img406/3696/screenshot20090915at447.png
With Mode of Aspect Fit on the UIImageView
alt text http://img406.imageshack.us/img406/9373/screenshot20090915at447e.png
With Center, the size of the image seems correct but you can see that it goes out of the UIImageView which has a red UIView underneath it and is actually 2px on each side larger than the image view. But with the Aspect Fit, it makes the image smaller so that it fits inside. But I don't understand why it would make it smaller if it is already small enough to fit.
Sorry for wasting anyone's time. Turns out I didn't try all of the content modes. Seems that Content Mode of Bottom top works. This is backwards from how I understood it. Thanks for all your help.
Try this. Change your UIImageView to be the same size as the UIImage that you are going to load, then position the UIImageView so that it's centered. This is the approach I've taken since I find UIImageView to be a bit funny to work with. Or, if you prefer, skip the UIImageView and just draw the UIImage using it's - (void)drawInRect:(CGRect)rect method.
Sounds like your image contains transparent areas, at least at the bottom, which shift the image off center.
Edit: Also, you should check that the resolution of the image is set to 72dpi.