Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

Thread: Creating A Grid
View Single Post
Old 01-27-2010, 07:58 AM   #13 (permalink)
evmacdev
Registered Member
 
Join Date: Jan 2010
Posts: 6
evmacdev is on a distinguished road
Default

Quote:
Originally Posted by ng93 View Post
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //run when the user taps the screen
	UITouch *touch = [touches anyObject]; //the users touch (or first touch if they are using > one finger)
	CGPoint touchPosition = [touch locationInView:self.view]; //the position of the touch
	CGFloat cellHeight = 20; //the width of the individual cells (all cells must be the same width and height for this to work)
	CGFloat cellWidth = 20; //the height of the individual cells
	int amountCellsWidth = 50; //how many cells you have in each row
	int amountCellsHeight = 50; //how many cells you have in each column
	for (int x=0; x<amountCellsWidth; x++) { //repeats the following code for the integer amountCellsWidth
		for (int y=0; y<amountCellsHeight; y++) {//repeats the following code for the integer amountCellsHeight
			if (touchPosition.y > y*cellHeight && touchPosition.y < (y+1)*cellHeight && touchPosition.x > x*cellWidth && touchPosition.x < (x+1)*cellWidth) { //works out if the touch was to the right of the cell's x position, to the left of the cells x position + the cells width, underneath the cells y position and above the cells y position + the cells height
				[cell[x][y] setImage:yourImage]; //sets the tapped cells image to the UIImage yourImage
			}
		}
	}
}
hope this helps
ng93
Thanks will try it
evmacdev is offline   Reply With Quote
 

» Advertisements
» Online Users: 484
19 members and 465 guests
AyClass, chemistry, djohnson, Free App Monster, G-Power, Hassasin, HemiMG, HowEver, iacemomo, ilmman, mediaspree, mezzh, raheel, simplymuzik3, SLIC, stanny, timle8n1, yomo710, yvonneolivia
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,439
Threads: 94,026
Posts: 402,591
Top Poster: BrianSlick (7,978)
Welcome to our newest member, mezzh
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:36 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.