Thursday, June 17, 2010

Grid Tile Images in Scroll View .

#define TILE_WIDTH 78
#define TILE_HEIGHT 80
#define TILE_SPACING 2
#define POSITION 0


-(void)viewDidLoad{
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(5.0f, 60, 310.0f,480 )];
[scrollView setContentSize:CGSizeMake(310.0f, 600.0f)];
scrollView.showsVerticalScrollIndicator=YES;
scrollView.scrollEnabled=YES;
//scrollView.exclusiveTouch=YES;
scrollView.userInteractionEnabled=YES;
scrollView.scrollsToTop=YES;
scrollView.delegate=self;
scrollView.backgroundColor=[UIColor clearColor];
scrollView.indicatorStyle=UIScrollViewIndicatorStyleWhite;

[self setTilesImages];
}
-(void)setTilesImages
{
for( int x=0; x<13; x++ )
{
int temp,temp2;
temp = ( TILE_HEIGHT * (x/4) );
temp2 = ((TILE_HEIGHT + TILE_SPACING) * (x/4) ) + POSITION + 63 ;
CGRect tileFrame = CGRectMake(( TILE_WIDTH + TILE_SPACING) * (x%4), temp2, TILE_WIDTH, TILE_HEIGHT );

self.view.backgroundColor=[UIColor grayColor];

*************************
Two Types USes For display on custom button and UIImageView: Please choose one type :
*************************
//On Custom Button
*****************************************************************************
buttonOnScrollView = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonOnScrollView setFrame:tileFrame]; // position in the parent view and set the size of the button 0,63,78,80
[buttonOnScrollView setImage:[UIImage imageNamed:@"baby.png"] forState:UIControlStateNormal];
// add targets and actions
[buttonOnScrollView addTarget:self action:@selector(callZoomView:) forControlEvents:UIControlEventTouchUpInside];
[buttonOnScrollView setTag:x];
NSLog(@"buttonOnScrollView tag is : %d ", buttonOnScrollView.tag);

[scrollView insertSubview:buttonOnScrollView atIndex:x];


*************************************************************
// On UIImage View
**************************************************************
UIImageView *imageView = [[UIImageView alloc] initWithFrame:tileFrame];
imageView.userInteractionEnabled=YES;
imageView.image = [UIImage imageNamed:@"TestImage1.jpg"];
[scrollView insertSubview: imageView atIndex:x];

**************************************************************
}
[self.view addSubview:scrollView];

}

-(void)callZoomView:(id)sender
{



NSLog(@"buttonOnScrollView tag is : %d ", [sender tag]);
}

Regards,
Dinesh Sharma

1 comment:

  1. hi dinesh,

    check the code available at

    https://code.google.com/p/iphone-async-httpserver

    in that just uncomment the code in
    - (void) callBackTargetSelector0:(NSData*)data

    and comment the code in
    - (void) callBackTargetSelector1:(NSData*)data

    and run the code, check out how the grid design have been made along with dynamic downloading of the images

    ReplyDelete