Update UIImageView in a UITableView cell with transparency - ios

I have an imageview class that subclasses the UIImageView class, it is being displayed in an UITableView that dequeueReusableCellWithIdentifier.
#interface ImageView : UIImageView {
.
.
.
when it is time to update the image from one image to another, the update itself works
[self setImage:[UIImage imageWithContentsOfFile:[self resourcesDir:url]]];
but my images are transparent PNG (with the same dimensions) so part of the pervious image is visible under the updated one (since the cells themselves are reused)
I tried various ways to make the imageView clear itself first, but none work, this is what I tried:
self.image = nil;
[self setBackgroundColor:[UIColor clearColor]];
[self setNeedsDisplay];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
Any Idea ?

Be sure you are NOT using a new instance of the UIImageView. It must be the same instance for your code to work properly. You idea sounds like it should work properly.

Related

Blur for different UIImages in same UITableViewCell

So in my custom UITableViewCell I have 4 different UIImageView's & for each UILongTapGestureRecognizer.
Table View Cells before adding images
After I add images and table looks like this :
Table View Cells after adding images
I need to be able to delete image after long tap gesture recognizer, when the chosen image blurs out and remove button is shown.
I've added the long press gesture recognizer method and while I understand that I need to apply blur to the chosen image and not the UIImageView itself, I dont seem to get how to pass the reference of the picked image to the cell so that I can apply the blur filter to the image.
Is delegate legitimate to use in this case?
In order to apply blur effect as you mentioned you need the image itself.
You can try something like this :)
UIImage *image = [yourImageView image];
UIImage *blurredImage = [UIImageEffects imageByApplyingBlurToImage:image withRadius:30 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
yourImageView.image = blurredImage;
You can get UIImageEffects apple file from here :)
https://developer.apple.com/library/ios/samplecode/UIImageEffects/Listings/UIImageEffects_main_m.html
Hope it helps :)

Images in UITableView cells are not honoring tintColor

I have a UITableView which is comprised of static cells. In IB I've set each UITableViewCell's style to "Basic" and set an image (see screenshot). The buttons in my nav bar honor the tintColor property but the images in the tableview do not. Thus far I've done everything in IB - do I have to use code if I want the images to honor the tintColor property too?
Thanks
Every UIImageView has the property tintColor on iOS7+
Try to set cell's imageView.image.renderingMode to UIImageRenderingModeAlwaysTemplate in storyboard User Defined Runtime Attributes
What a headache this problem is after so many versions! The only thing that is a sure fire fix, assuming everything is "right" (template image, etc) is subclassing the UIImageView and overriding didMoveToSuperview with this...
- (void)didMoveToSuperview
{
[self setHighlighted:YES];
[self setHighlighted:NO];
[super didMoveToSuperview];
}
It's a hack but it works.
Here is an example:
UIImage *image = [[UIImage imageNamed:#"ic_email_white"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[[cell imageView] setImage:image];
[[cell imageView] setTintColor:[UIColor redColor]];
The below setup worked for me well.
In the storyboard, set cell's contentView tintColor as your desired color and UIImagview's tintColor as default.

scrollView with UIImage respond touch

I'm using a simple code to add some images to my UIScrollView. Also I've implemented another code to detect touches on each image.
Here is the code:
(void)handleSingleTap:(UIGestureRecognizer *)sender
{
int senderTagIs;
senderTagIs = sender.view.tag;
if (sender.view.layer.borderColor != [UIColor cyanColor].CGColor) {
sender.view.layer.borderColor = [UIColor cyanColor].CGColor;
UIImageView *showFullImage = (UIImageView *)[self.view viewWithTag:sender.view.tag+100];
[showFullImage setTag:sender.view.tag+200];
[self.view addSubview:showFullImage];
showFullImage.hidden = NO;
NSLog(#"Show tag is: %i", sender.view.tag);
}
else
{
sender.view.layer.borderColor = [UIColor whiteColor].CGColor;
UIImageView *hideFullImage = (UIImageView *)[self.view viewWithTag:sender.view.tag+200];
[hideFullImage setTag:sender.view.tag+100];
hideFullImage.hidden = YES;
NSLog(#"Hide tag is: %i", sender.view.tag);
}
}
The above code, sets the border color to cyan and show my small images from UIScrollView, in another UIImageView.
But my problem is, that I can't set the option to hide all images and set border color white for all images when one image is touched.
Ex: If I touch the first image, then the code will work, my big UIImageView will show touched image and touched image from UIScrollView will get the cyan color for border, so far so good.
Now, If I touch third image, my first image is shown, the color border is cyan, and so... I have to touch first image again to disable, but this is not what I want.
So, we've got a few things going on here. First, I'm assuming you're trying to show a collection of images in a scroll view with some custom padding to indicate selection around them. This sounds tailor make for using UICollectionView with a custom cell.
Absent further information, you're not resetting the old color. Either keep a reference to a selected image as a class variable or, assuming your image views are in a collection object like an NSArray, begin your method by iterating through the objects and resetting their view to an unselected state.
If you just need to hack together a solution, the second option should work. I really recommend using UICollectionView. It's a bit more work in the beginning, especially if you're not experienced with it, but it's well worth learning. Here's a good tutorial on UICollectionView.

UIImageView doesn't remove old image when going back with the navigation control

I have a UIImageViews within a UIScrollView. Tapping an image moves to another view controller where I can edit info that will then change the original tapped UIImage.
When I go back via the nav controller the new image does appear (dependent on the changes made in the 2nd view controller) however the old image also appears behind it.
If I go back another level then forward again the old image is now gone. How can I fix this without have to go back and forth?
(the code is long and complex so don't know if it will help to post it)
Found it used
-(void) viewDidDisappear: (BOOL) animated {
[super viewDidDisappear:animated];
for (UIImageView *img in [MyScrollView subview]) {
[img removeFromSuperview];
}
}
try this in viewDidDisappear
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[imageView setImage:[UIImage imageNamed:#""]];
}
then before you set new image empty or nill the image view like this
imgview.image=nil;
then set new image i hope this is work if any problem then comment :-)

UIView::addSubView obstructs the navigation bar originally at the top

I designed a very simple interface for an ipad device: UIView + a navigation bar.
Then after the view is load, it will download an image from a location and use the following method to display it:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
UIImage* testImg = [UIImage imageWithData:_networkData];
UIImageView* testView = [[UIImageView alloc] initWithImage:testImg];
[_view addSubview:testView];
[testView release];
}
The problem is now the new UIImage occupies the whole visible area of the Ipad.
I wonder how can I fix this issue? I suppose I have to find out the frame of the display area in the original view, and then assign it to the UIImageView instance?
initWithImage will automatically adjust the frame to match the size of the image you're passing in. To tell the UIImageView to take the same size as its parent view you could just add the following line before you add the subview:
testView.frame = _view.bounds
...we use bounds rather than frame because the superview may have an offset that we don't want the image view to have.

Resources