I've build this keyboard and in the picture you can see it, it's the number 1 but I want to it become number 2.
I write with taking the title of every button so button A is titled A and when clicked it will display A in the large label that I have over those empty boxes, the empty boxes are UIview.
Does someone knows in which way to get this working do I have to use different layers? or whatever because I don't know.
hope someone can tell me here is the picture:
http://img213.imageshack.us/img213/4500/questionow.png
thanks
EDIT
This is what I got now .h
IBOutlet UIImageView *imageview1;
IBOutlet UIImageView *imageview2;
IBOutlet UIImageView *imageview3;
IBOutlet UIImageView *imageview4;
IBOutlet UIImageView *imageview5;
IBOutlet UIImageView *imageview6;
}
-(IBAction)showA;
-(IBAction)showB;
-(IBAction)showC;
-(IBAction)showD;
-(IBAction)showE;
-(IBAction)showF;
-(IBAction)showG;
-(IBAction)showH;
-(IBAction)showI;
-(IBAction)showJ;
-(IBAction)showK;
-(IBAction)showL;
-(IBAction)showM;
-(IBAction)showN;
-(IBAction)showO;
-(IBAction)showP;
-(IBAction)showQ;
-(IBAction)showR;
-(IBAction)showS;
-(IBAction)showT;
-(IBAction)showU;
-(IBAction)showV;
-(IBAction)showW;
-(IBAction)showX;
-(IBAction)showY;
-(IBAction)showZ;
.m
-(IBAction)showA {
UIImage *img = [UIImage imageNamed:#"A.png"];
[imageview1 setImage:img];
}
-(IBAction)showB {
UIImage *img = [UIImage imageNamed:#"B.png"];
[imageview1 setImage:img];
}
Etc.
got UIImageview over the empty box and the first letters are shown very nice
Watched some tutorials on mutable arrays but still not sure how to implant it in my code.
Would it be a mutable array with imagevie1, 2,3,4,5,6?
hope you can help me out again
This is more about organizing your thoughts than actually technical stuff.
1) Check how many boxes are filled, so you know what's the next box to be filled.
2) Have a way to access each box.
Edit 1: Building the Data Source
This is just a way to get your started:
1) Start by creating an NSMutableArray.
2) When you click any button, using the size of your NSMutableArray, you can automatically know where the image should be placed:
myArray count = 0 => UIImageView 0 needs to be filled
myArray count = 1 => UIImageView 1 needs to be filled
myArray count = 2 => UIImageView 2 needs to be filled
myArray count = 3 => UIImageView 3 needs to be filled
Related
I have an outlet called myImage for an imageView that is set up with an animation of 5 images. With a Tap Gesture Recognizer on it, I want to have the users tap on the correct image as it quickly passes to move onto the next level.
There is an error in my code and this does not work:
- (void)viewDidLoad {
[super viewDidLoad];
self.myImage.animationImages =
[NSArray arrayWithObjects:
[UIImage imageNamed:#"examplePic1.png"],
[UIImage imageNamed:#"examplePic2.png"],
[UIImage imageNamed:#"correctPic.png"],
[UIImage imageNamed:#"examplePic4.png"],
[UIImage imageNamed:#"examplePic5.png"],
nil];
[self.myImage setAnimationRepeatCount:0];
self.myImage.animationDuration = 1;
[self.myImage startAnimating];
}
- (IBAction)TapGestureRecognizer:(id)sender {
if (self.myImage.image = [UIImage imageNamed:#"correctPic.png"]) {
// Launch next level
}
else {
// Vibrate Device and subtract points from score
}
}
You have a fundamental misconception in your code about objects and equality. I assume that you meant "==" in your TapGestureRecognizer method. However, even if you changed the = to == would not give you what you want.
The expressions like
[UIImage imageNamed:#"examplePic1.png"]
call a class method of UIImage that creates a new UIImage object. You have created 5 of these objects, put them into an array, an set the animationImage array of your UIImage object to these images. These objects are all different objects from myView.image: I can tell because I can see from your code that you have assigned 5 new objects to the animationObjects array. Your == test cannot ever work because you are comparing self.image to a brand new UIImage object.
What you are trying to do is determine which image the user touched. There is no method in UIImageView that tells you which animation UIImage is currently showing. You are assuming that the image property of the view will be changed as the animation images are displayed, but there is no reason for this assumption to be true: it is certainly not stated in the documentation. Even if you corrected your code (by doing something like this):
if(self.image == [self.animationImages objectAtIndex:2]){
}
your code would not be correct.
If I were trying to do what you want, I would create a UIView with 5 UIImageView as subview, each with their own gesture recognizer. I would use the frame property of each subview to do my animation.
Looks like the options are to determine which image "should" be showing based upon the startTime of the animation.
Determine which of its animationImages a UIImageView is displaying?
Or, just use a timer to set the currently displayed image.
Detect which image was clicked in UIImageView with animationImages
I have properly connected a UIImageView to a prototype cell as a weak IBOutlet but I can't have it shown on both the simulator and device when I run the program.Things get even more weird when I try to delete the prototype cell and rebuild it back, but have other items (e.g.:UIButtons,UILabels) not showing up.
Tried "clean", "clean build folder", deleted the app from my device, and even deleted the "derived data" folder from my mac but to no avail. Even tried fitting in a new UILabel to the cell and have it not showing up!
I have made sure that:
The items are properly connected to my cell .h file as weak, nonatomic IBOulets as the following:
#property (weak, nonatomic) IBOutlet UIImageView *coverImage;
#property (weak, nonatomic) IBOutlet UILabel *activityLabel;
The cellForRowAtIndexPath is properly done:
{
NewsFeedCell * cell = [tableView dequeueReusableCellWithIdentifier:#"NewsFeedCell" forIndexPath:indexPath];
if (self.dataInStorage)
{
NSDictionary * newsFeedData = (NSDictionary*) [NSKeyedUnarchiver unarchiveObjectWithData:self.dataInStorage];
NSDictionary * dataToDisplay = [[newsFeedData objectForKey:#"Content"] objectAtIndex:indexPath.row];
//ActivityLabel
NSInteger typeID = [[dataToDisplay objectForKey:#"TypeID"] integerValue];
switch (typeID)
{
case 3:
cell.activityLabel.text = [NSString stringWithFormat:#"created an event - %#", [dataToDisplay objectForKey:#"Title"]];
break;
case 7:
cell.activityLabel.text = [NSString stringWithFormat:#"added a listing - %#", [dataToDisplay objectForKey:#"Title"]];
break;
default:
break;
}
//CoverImage
UIImage * coverImage = [UIImage imageWithData:[dataToDisplay objectForKey:#"CoverImage"]];
CGImageRef cgref = [coverImage CGImage];
CIImage *cim = [coverImage CIImage];
if (!(cim == nil && cgref == NULL))
{
//Image is available
cell.coverImage.image =[UIImage imageWithData:coverImage];
}
}
return cell;
I think the problem maybe in the config or storyboard settings, though I can't figure out still after more than 10 hours. Anyone needing the source code to take a look, please let me know so that I can send you the whole folder.
Need help!
Check the size of UIImageView in Identity Inspector (present in right side of Xcode).
Sometimes its (width,height) becomes (0,0) automatically.
Ok, i have found what i think is the fault here.
Disconnect the Cover image outlet connection,
Create a new ImageView and drop it in the storyboard. Create the connection with the class and the outlet. That should do it.
It seems you have copy pasted the outlets from another view, Please disconnect all connections and reconnect them with your class (newsFeedcell) and the outlets in the storyboard once again. Doing this will prevent future conflicts.
Cheers, Hope this solves it
[EDIT]
write this code.
cell.imageview.image = coverimage
Gotten an answer from #Paulw11 after posting the question in another thread. Apparently I had mistakenly added in items into the cell when my size is configured to reg-reg, instead of the usual any-any I use. Certainly, those items will not be visible on my iPhone device! (reg-reg will make those items visible only on iPad devices) Future coders beware!
Thanks again to #Paulw11 for the great help. And also #LightYagami and #AashishTamsya for the effort.
Cheers!
Link to the other thread: iOS: Items in custom UITableViewCell not showing up consistently. Storyboard bug?
I have an image called Empty.png, it is a small-ish square tile, how could I instantiate the image to appear at several different points on the screen?
Thank you for any help in advance :)
You can can place UIImageView's wherever you want the image to appear.And then set the image property of each image view as this image. (UIImage object).
If you are using interface builder then you just have to type in the name of the file in the attributes inspector of the imageview in the interface builder.
Or you could do this:
UIImage *img = [UIImage imageName:#"Empty.png"];
imageView.image = img; //Assuming this is your utlet to the image view.
It depends on how you want to use it.
If you just draw it with core graphics, let's say in drawInRect: or so, then you simply draw it several times.
If you want to display it within one or a number of image views, then instanciate your UIImageViews and assign the same object to all of them. Or let the Interface Builder do the instanciation for you. But you cannot add a single UIView object several times to one or a number of subview-hierarchies. If you add a UIView as subview to a view then it will disappear from the position where it was before.
10 UIImageView may use the same UIView but you need 10 UIImageViews to display all of them.
The same applies to UIButtons and every UI-thing that has an image or background image.
this will get you one image into some view
CGPoint position = CGPointMake(x,y);
UIImageView *img = [[UIImageView alloc] init];
img.image = [UIImage imageNamed:#"Empty.png"];
img.frame = CGRectMake(position.x, position.y, img.image.size.width, img.image.size.height);
[someUIView addSubview:img];
if you make an array for the positions (x,y) of all the images, then you can just run it in a for loop and it will place the images into the view at the positions you want
note: CGPoints cant be stored in an NSArray since its not an NSObject type, either use a C/C++ array or use something else that can fit into a NSArray
I made 26 buttons, A-Z and when I click them the image of the button I pressed will display in an image view, when I click A, it displays A, When I click B it will display B etc.
The problem I have is that they won't display next to each other, I have 6 image views and I want the first letter to fill first box second letter second box etc.
I just don't know how to do this, I've been trying a lot of ways now and i'm pretty sure i'll need to use arrays just can't get the code right.
This is a picture of where I am now I'm already past number 1 so it's like number 2 except for showing next each other ofc.
hope someone can tell me here is the picture:
http://img213.imageshack.us/img213/4500/questionow.png
thanks
This is what I got now .h
IBOutlet UIImageView *imageview1;
IBOutlet UIImageView *imageview2;
IBOutlet UIImageView *imageview3;
IBOutlet UIImageView *imageview4;
IBOutlet UIImageView *imageview5;
IBOutlet UIImageView *imageview6;
}
-(IBAction)showA;
-(IBAction)showB;
-(IBAction)showC;
-(IBAction)showD;
-(IBAction)showE;
-(IBAction)showF;
-(IBAction)showG;
-(IBAction)showH;
-(IBAction)showI;
-(IBAction)showJ;
-(IBAction)showK;
-(IBAction)showL;
-(IBAction)showM;
-(IBAction)showN;
-(IBAction)showO;
-(IBAction)showP;
-(IBAction)showQ;
-(IBAction)showR;
-(IBAction)showS;
-(IBAction)showT;
-(IBAction)showU;
-(IBAction)showV;
-(IBAction)showW;
-(IBAction)showX;
-(IBAction)showY;
-(IBAction)showZ;
.m
-(IBAction)showA {
UIImage *img = [UIImage imageNamed:#"A.png"];
[imageview1 setImage:img];
}
-(IBAction)showB {
UIImage *img = [UIImage imageNamed:#"B.png"];
[imageview1 setImage:img];
}
Etc.
Hope someone can tell me how to make this or has some sample code for me because I don't quite get the arrays even after seeing a lot of tutorials on them.
thanks Don
You could always do:
- (void)setNextImage:(UIImage *)image {
if (imageview1.image == nil) {
[imageView1 setImage:image]
} else if (imageView2.image == nil){
[imageView2 setImage:image]
} // ... Through all 6 images
}
and then in each of your button actions just call:
[self setNextImage:img];
instead of setting it directly.
Using an array is not hard. Just declare either a standard C array of UIImageView* or an NSArray, inited like: [NSArray arrayWithObjects:imageView1, imageView2 ... imageView6, nil].
Then have a position counter pos declared at the instance level, and you simply do:
[imageViewArray objectAtIndex:pos].image = imageParm; pos++;
(Or, for the C array, imageViewArray[pos].image = imageParm; pos++;.)
My app has around 100 Picture. Each picture is around 150 KB.And I just want to swipe each picture to go next or back to previous pic.
What is the best way that use less memory and CPU load ???
Assuming you have all images within application, all image names stored in NSMutableArray.
Take one UIImageView wired up as IBOutlet on your XIB file.
NSMutableArray *imgNameArr; //Array to store image names
NSInteger currShowing; //Integer value to keep track of image currently being displayed.
//Function to change image when swipe right
-(void)swipeRight
{
if(currShowing<[imgNameArr count])
{
currShowing+=1;
self.yourDisplayImageView.image = [UIImage imageNamed:[imgNameArr objectAtIndex:currShowing]];
}
}
//Function to change image when swipe left
-(void)swipeLeft
{
if(currShowing>0)
{
currShowing-=1;
self.yourDisplayImageView.image = [UIImage imageNamed:[imgNameArr objectAtIndex:currShowing]];
}
}
Please do leave comment for any query.
Hope it helps.