how to display lable under image
<p>hi i am new to iPhone. what i need is display the name under selected image at imageview from grid but it displayed under gridview pls help me i tried this from one weak onwards  plsssss plss help me this is my code</p>

<hr>

<p>//
//  CustomImagePicker.h
//  CustomImagePicker
//
//  Created by Ray Wenderlich on 1/27/10.
//  Copyright 2010 Ray Wenderlich. All rights reserved.
//</p>

<h1>import </h1>

<p>@interface CustomImagePicker : UIViewController {
    NSMutableArray *_images;
    NSMutableArray *_thumbs;
    UIImage *_selectedImage;</p>

<p>}</p>

<p>@property (nonatomic, retain) NSMutableArray *images;
@property (nonatomic, retain) NSMutableArray *thumbs;
@property (nonatomic, retain) UIImage *selectedImage;</p>

<ul>
<li><p>(IBAction)buttonClicked:(id)sender;</p></li>
<li><p>(void)addImage:(UIImage *)image;</p></li>
</ul>

<h2>@end</h2>

<p>//
//  CustomImagePicker.m
//  CustomImagePicker
//
//  Created by Ray Wenderlich on 1/27/10.
//  Copyright 2010 Ray Wenderlich. All rights reserved.
//</p>

<h1>import "CustomImagePicker.h"</h1>

<h1>import "CustomImagePickerAppDelegate.h"</h1>

<h1>import "UIImageExtras.h"</h1>

<p>@implementation CustomImagePicker
@synthesize images = _images;
@synthesize thumbs = _thumbs;
@synthesize selectedImage = _selectedImage;</p>

<ul>
<li><p>(id) init {
if ((self = [super init])) {
    _images =  [[NSMutableArray alloc] init];
    _thumbs =  [[NSMutableArray alloc] init];</p>

<p>}
return self;
}</p></li>
<li><p>(void)addImage:(UIImage *)image {
[_images addObject:image];
[_thumbs addObject:[image imageByScalingAndCroppingForSize:CGSizeMake(80, 80)]];
}</p></li>
<li><p>(void)viewDidLoad {</p>

<p>// Create view
UIScrollView *view = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; </p>

<pre><code>int row = 0;
</code></pre>

<p>int column = 0;
for(int i = 0; i &lt; _thumbs.count; ++i) {</p>

<pre><code>UIImage *thumb = [_thumbs objectAtIndex:i];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*100+24, row*80+12, 70, 70);
[button setImage:thumb forState:UIControlStateNormal];
[button addTarget:self 
           action:@selector(buttonClicked:) 
 forControlEvents:UIControlEventTouchUpInside];
button.tag = i; 
[view addSubview:button];


if (column == 2) {
    column = 0;
    row++;
} else {
    column++;
}
</code></pre>

<p>}</p>

<p>[view setContentSize:CGSizeMake(320, (row+1) * 80 + 10)];</p>

<p>self.view = view;
[view release]; </p></li>
</ul>

<p>}</p>

<ul>
<li><p>(IBAction)buttonClicked:(id)sender {
UIButton *button = (UIButton *)sender;</p>

<p>self.selectedImage = [_images objectAtIndex:button.tag];</p>

<p>CustomImagePickerAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navController popViewControllerAnimated:YES];</p></li>
</ul>

<p>}</p>

<ul>
<li><p>(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}</p></li>
<li><p>(void)viewDidUnload {
}</p></li>
<li><p>(void)dealloc {
self.images = nil;
self.thumbs = nil;
self.selectedImage = nil;
[super dealloc];
}</p></li>
</ul>

<h2>@end</h2>

<p>//
//  CustomImagePickerViewController.h
//  CustomImagePicker
//
//  Created by Ray Wenderlich on 1/27/10.
//  Copyright Ray Wenderlich 2010. All rights reserved.
//</p>

<h1>import </h1>

<p>@class CustomImagePicker;</p>

<p>@interface CustomImagePickerViewController : UIViewController {
    UIImageView *_imageView;
    CustomImagePicker *_imagePicker;
    NSTimer *atimer;</p>

<p>}</p>

<p>@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) CustomImagePicker *imagePicker;
@property (nonatomic, retain) NSTimer *atimer;</p>

<h2>@end</h2>

<p>//
//  CustomImagePickerViewController.m
//  CustomImagePicker
//
//  Created by Ray Wenderlich on 1/27/10.
//  Copyright Ray Wenderlich 2010. All rights reserved.
//</p>

<h1>import "CustomImagePickerViewController.h"</h1>

<h1>import "CustomImagePicker.h"</h1>

<h1>import "CustomImagePickerAppDelegate.h"</h1>

<p>@implementation CustomImagePickerViewController</p>

<p>@synthesize imageView = _imageView;
@synthesize imagePicker = _imagePicker;
@synthesize atimer;</p>

<ul>
<li><p>(void)viewDidLoad {</p>

<p>// Initialize image picker
_imagePicker = [[CustomImagePicker alloc] init];</p>

<pre><code>// Add images to the picker
</code></pre>

<p>// Note that this can take time due to resizing for thumbnails, so for production you
// should either: a) have full-size and thumbs for each image pre-made, or:
//                b) put a loading indicator in as this code runs</p>

<p>[_imagePicker addImage:[UIImage imageNamed:@"bear_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"bafflo_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"cat_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"camel_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"cow_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"dog_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"deer_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"elephant_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"fox_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"goat.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"gorilla_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"horse.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"frog.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"lion_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"monkey_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"rabbit_large.jpg"]];<br>
[_imagePicker addImage:[UIImage imageNamed:@"rahino_large.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"rat.jpg"]];<br>
[_imagePicker addImage:[UIImage imageNamed:@"snake.jpg"]];
[_imagePicker addImage:[UIImage imageNamed:@"squrillel.jpg"]];<br>
[_imagePicker addImage:[UIImage imageNamed:@"tiger_large.jpg"]];    </p>

<p>[_imagePicker addImage:[UIImage imageNamed:@"zebra_large.jpg"]];    </p>

<p>CustomImagePickerAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *navController = [delegate navController];
[navController pushViewController:_imagePicker animated:YES];
self.navigationController.navigationBarHidden=YES;  </p>

<p>[super viewDidLoad];</p>

<p>atimer = [NSTimer scheduledTimerWithTimeInterval:3.0 
                                          target:self
                                        selector:@selector(runscheduledTask)
                                        userInfo:nil
                                         repeats:YES];</p></li>
</ul>

<p>}</p>

<ul>
<li><p>(void)runscheduledTask {</p>

<p>NSLog(@"timer");
@try {  </p>

<p>CustomImagePickerAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *navController = [delegate navController];
[navController pushViewController:_imagePicker animated:YES];</p>

<p>}</p></li>
</ul>

<p>@catch (NSException * e){
}
}   </p>

<ul>
<li><p>(void)viewWillAppear:(BOOL)animated {</p>

<p>_imageView.image = _imagePicker.selectedImage;</p></li>
</ul>

<p>}</p>

<ul>
<li>(void)viewDidUnload {
self.imageView = nil;</li>
</ul>

<p>}</p>

<ul>
<li>(void)dealloc {
[_imageView release];
_imageView = nil;
[_imagePicker release];
_imagePicker = nil;
 [atimer release];
 [atimer invalidate]; 
 [super dealloc];
}</li>
</ul>

<h2>@end</h2>

<p>//
//  CustomImagePickerAppDelegate.h
//  CustomImagePicker
//
//  Created by Ray Wenderlich on 1/27/10.
//  Copyright Ray Wenderlich 2010. All rights reserved.
//</p>

<h1>import </h1>

<p>@class CustomImagePickerViewController;</p>

<p>@interface CustomImagePickerAppDelegate : NSObject  {
    UIWindow *window;
    UINavigationController *navController;
}</p>

<p>@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;</p>

<h2>@end</h2>

<p>//
//  CustomImagePickerAppDelegate.m
//  CustomImagePicker
//
//  Created by Ray Wenderlich on 1/27/10.
//  Copyright Ray Wenderlich 2010. All rights reserved.
//</p>

<h1>import "CustomImagePickerAppDelegate.h"</h1>

<h1>import "CustomImagePickerViewController.h"</h1>

<p>@implementation CustomImagePickerAppDelegate</p>

<p>@synthesize window;
@synthesize navController;</p>

<ul>
<li><p>(void)applicationDidFinishLaunching:(UIApplication *)application {    </p>

<p>// Override point for customization after app launch<br>
[window addSubview:navController.view];
[window makeKeyAndVisible];
}</p></li>
<li><p>(void)dealloc {
[navController release];
[window release];
[super dealloc];
}</p></li>
</ul>

<h2>@end</h2>

<p>// From cscade on iphonedevbook.com forums
// And Bjorn Sallarp on blog.sallarp.com</p>

<p>@interface UIImage (Extras)</p>

<ul>
<li>(UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize;</li>
</ul>

<h2>@end</h2>

<h1>import "UIImageExtras.h"</h1>

<p>@implementation UIImage (Extras)</p>

<ul>
<li><p>(UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
UIImage *sourceImage = self;
UIImage *newImage = nil;<br>
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);</p>

<p>if (CGSizeEqualToSize(imageSize, targetSize) == NO) 
{
    CGFloat widthFactor = targetWidth / width;
    CGFloat heightFactor = targetHeight / height;</p>

<pre><code>if (widthFactor &gt; heightFactor) 
    scaleFactor = widthFactor; // scale to fit height
else
    scaleFactor = heightFactor; // scale to fit width
scaledWidth  = width * scaleFactor;
scaledHeight = height * scaleFactor;


// center the image
if (widthFactor &gt; heightFactor)
{
    thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; 
}
else 
    if (widthFactor &lt; heightFactor)
    {
        thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
    }
</code></pre>

<p>}       </p>

<p>UIGraphicsBeginImageContext(targetSize); // this will crop</p>

<p>CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width  = scaledWidth;
thumbnailRect.size.height = scaledHeight;</p>

<p>[sourceImage drawInRect:thumbnailRect];</p>

<p>newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil) 
    NSLog(@"could not scale image");</p>

<p>//pop the context to get back to the default
UIGraphicsEndImageContext();
return newImage;
}</p></li>
</ul>

<h2>@end</h2>

<p>thank u  very much in advance</p>
