I have a UIImageView that I have already set an image to. This works fine, but later, I want to change that image. So, I set a new image for the image property, but when I view the app, that image is set as a second image over the first:
UIImageView *image;
image = (UIImageView *)[cell viewWithTag:0];
image.image = [UIImage imageNamed:#"History_Row2.png"];
How can I replace the current image in my UIImageView rather than seeming to add another?!
I did it by retaining the UIImageView, and keeping a reference as an ivar, releasing on dealloc.
image = (UIImageView *)[cell viewWithTag:0];
That was returning a UITableViewCell rather than a UIImageView, this is because the tag 0 is the default and it needs to be changed to a different number. After doing this it worked.
Related
I have an UIImage above which I am supposed to add another UIImage programmatically, above which there will be an UILabel. I successfully added the Image but it overlaps the Label.
If 1. BG image 2.Image to be added programmatically 3. Label,
then the sequence I want is,
1
2
3
and what I get is
1
3
2
2 overlaps my Label. I have tried Send to Back, Bring to Front and bringSubviewToFront. It did not work.
UIImageView *img2=[[UIImageView alloc] initWithImage: [UIImage imageNamed: #"TDK 3 Speaker.png"]];
//img2.backgroundColor=[UIColor clearColor];
[BgImage addSubview:img2];
UILabel *lblText=[[UILabel alloc]initWithFrame:CGRectMake(200, 0, 200, 40)];
lblText.text=#"I am Here";
//lblText.backgroundColor=[UIColor clearColor];
[BgImage addSubview:lblText];
What you should do is add the particular images in that sequence itself, i.e. in the ViewWillAppear or the ViewDidLoad method use the method
self.view addSubview:BGimage .
Then add the next image on the previous one like
BGimage addSubview:image2 .
Similarly add the UILabel on the Image 2 like
Image2 addSubview:Label
This will put your images and the label in the particular sequence you want :)
try this, add QuartzCore.framework and in your header file
#import <QuartzCore/QuartzCore.h>
and in you implementation file
your_Label.layer.zPosition=your_secondImage.layer.zPosition+1;
The order of adding is important here the later one comes in front
Add subview should be called in an order first BGImage then Image and then Label
If you want to show BG Image (1) then you can also use UIView instead of UIImageView You can also do the samething with UIImageView as well.
[yourUIView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"yourBackGroundImage"]]];
[yourUIView setFrame:CGRect(x,y,width,height)]; //yourExpectedFrame;
Now, create a UIImageView (2) with UIImage and also set a frame within that UIView, also create a UILabel (3) and give it frame as per the UIView and accordingly with UIImageView. That's all. You done!.
i m not sure,but you try this:
Set the property masksToBounds: YES for the UIImageView.
Before i click the image to pull the camera, i want to set up a default image on the imageview that shows a http://www.inc.com/images/avatar/default1.gif to inform that in that imageview goes a person image.
What is the best way to do this procedure?
Best regards.
If you are using a UIImageView the first thing is to create a UIImage object using this code
UIImage *defaultImage = [UIImage imageNamed:#"default.png"];
And then pass it to the UIImageView object if it is a property of your view controller you can use this(imageView is the variable name of UIImageView)
self.imageView.image = defaultImage;
If you are instantiating a new UIImageView in your view controller you can use this
UIImageView *imageView = [[UIImageView alloc] initWithImage:defaultImage];
UIImageView *theImageView;
//assuming that's the declaration in your header
//make sure default1.gif is inside your application bundle
//copied into the resources folder of your xcode project
//this code goes into your -viewDidLoad method
theImageView.image = [UIImage imageNamed:#"default1.gif"];
I have a tableView based app and I made a custom TableViewCell that have a thumbnail in it.
I wish to programmatically choose a default thumbnail image for my custom TableViewCell.
any ideas on how to do that?
Thanks.
Set tag for your UIImageView in your custom UITableViewCell, for example, let it be 10.
When you want to show image in that view for some UITableViewCell *cell; do next:
UIImageView *imageView = (UIImageView *)[cell viewForTag:10];
imageView.image = [UIImage ....];
- (void)setCellIconImage:(UIImage*)iconImage
{
self.imgView.image = iconImage;
}
I have a UIImageView with some lines (drawed by hand) and a background color. When i put the image of the UIImageView into a UIImage and save it to the photo library the background is white again. Is there any way to put the image property and the backGroundColor property of a UIImageView into one UIImage ?
It is possible to render the contents of an arbitrary UIView to an UIImage.
See http://www.icab.de/blog/2010/10/01/scaling-images-and-creating-thumbnails-from-uiviews/ for an implementation.
At the bottom of that page is a category for UIImage which, when imported, simply lets you create the UIImage from the UIView with UIImage *img = [UIImage imageFromView:someView];
How can i remove an ImageView added on a dynamically created UIView, so that i can add another ImageView on my UIView.
You either add a tag for that UIImageView and find it based on tag or loop throughout the subviews and look for an object of class UIImageView containing the image you need to change.
Easiest way is probably with tags. So...
UIImageView *removeMe = [[UIImageView alloc] init];
removeMe.image = [UIImage imageNamed:#"theImage.png"];
removeMe.tag = 1;
[theView addSubview:removeMe];
[removeMe release]; //theView now retains it!
...then later:
UIImageView *removalTarget = (UIImageView *)[theView viewWithTag:1];
[removalTarget removeFromSuperview];