Today I have written about how to make bookshelves look like UITableView
Initialise TableView
Give IBOutLate to UITableView and also give reference of delegate and datasource of tableview
Add several Images which name in Array
Initialize Array for table view
01 | titlesArray = [[ NSArray alloc] initWithObjects: @"People" , @"Things" , @"Fruits" , nil ]; |
02 | peopleArray = [[ NSArray alloc] initWithObjects: @"Gardener.png" , @"Plumber.png" , @"BusinessWoman.png" , @"BusinessMan.png" , @"Chef.png" , @"Doctor.png" , nil ]; |
03 | thingsArray = [[ NSArray alloc] initWithObjects: @"StopWatch.png" , @"TrashCan.png" , @"Key.png" , @"Telephone.png" , @"ChalkBoard.png" , @"Bucket.png" , nil ]; |
04 | fruitsArray = [[ NSArray alloc] initWithObjects: @"Pineapple.png" , @"Orange.png" , @"Apple.png" , nil ]; |
05 | categoryArray = [[ NSMutableArray alloc] initWithObjects: @"Bollywood" , @"GollyWood" , @"Dhollywood" , @"HollyWood" , @"TV Searials" , @"Sports" , @"Solo" , @"New" , nil ]; |
06 | _arFiltered = [[ NSMutableArray alloc] init]; |
07 | [_arFiltered addObjectsFromArray:categoryArray]; |
09 | arrays = [[ NSArray alloc] initWithObjects:peopleArray, thingsArray, fruitsArray, nil ]; |
10 | self .countries = [ NSDictionary dictionaryWithObjects:arrays forKeys:titlesArray]; |
11 | self .tableView.rowHeight = 250; |
12 | [ self .tableView reloadData]; |
Now define Delegate Method and make Table View
001 | - ( NSInteger )numberOfSectionsInTableView:(UITableView *)tableView |
003 | return [ self .countries count]; |
006 | - ( NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:( NSInteger )section |
008 | return [[ self .countries allKeys] objectAtIndex:section]; |
011 | - ( NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:( NSInteger )section |
018 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath { |
019 | static NSString *CellIdentifier = @"CountryCell" ; |
021 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
023 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; |
026 | NSString *continent1 = [ self tableView:tableView titleForHeaderInSection:indexPath.section]; |
027 | NSLog ( @"Contine............%@" , continent1); |
028 | int k = [[ self .countries valueForKey:continent1] count]; |
029 | UIScrollView *previewScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 250)]; |
030 | previewScrollView.backgroundColor = [UIColor clearColor]; |
031 | previewScrollView.pagingEnabled = TRUE; |
032 | previewScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
033 | [previewScrollView setContentSize:CGSizeMake(250*k, 60.0)]; |
034 | previewScrollView.showsHorizontalScrollIndicator = YES ; |
035 | NSLog ( @"cell.contentView.frame.size.widt %f" ,cell.contentView.frame.size.width); |
036 | NSLog ( @"K %@ %d" ,continent1, k); |
037 | for ( int i=0 ; i<k; i++ ){ |
044 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(250.0*i, 10, 200, 250)]; |
045 | imageView.image = [UIImage imageNamed:[[ self .countries valueForKey:continent1] objectAtIndex:i]]; |
046 | imageView.contentMode = UIViewContentModeCenter; |
047 | [previewScrollView addSubview:imageView]; |
049 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; |
050 | btn.frame = CGRectMake(250.0*i, 10, 200, 250); |
051 | NSLog ( @"%@" , [ NSString stringWithFormat: @"%d%d" ,indexPath.section,i]); |
052 | btn.tag = [[ NSString stringWithFormat: @"%d%d" ,indexPath.section,i] intValue]; |
053 | [btn addTarget: self action: @selector (btnTapped:) forControlEvents:UIControlEventTouchDown]; |
054 | [previewScrollView addSubview:btn]; |
057 | [[cell contentView] insertSubview:previewScrollView atIndex:0]; |
063 | -( void )btnTapped:( id )sender |
065 | int tag = [sender tag]; |
066 | NSLog ( @"Tag %d" , tag); |
068 | [detailView removeFromSuperview]; |
069 | detailView = [[UIView alloc] init]; |
070 | detailView.frame = CGRectMake(360, 360, 0, 0); |
071 | detailView.backgroundColor = [UIColor redColor]; |
072 | UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; |
073 | bgImage.backgroundColor = [UIColor grayColor]; |
074 | bgImage.image = [UIImage imageNamed: @"frnt-page.png" ]; |
075 | [detailView addSubview:bgImage]; |
077 | [ self .view addSubview:detailView]; |
080 | [UIView beginAnimations: nil context: nil ]; |
081 | [UIView setAnimationDuration:0.5]; |
082 | [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:detailView cache: YES ]; |
083 | [ self .view addSubview:detailView]; |
084 | [detailView setFrame:CGRectMake(150,150,360,360)]; |
085 | bgImage.frame = CGRectMake(0, 0, 360, 360); |
086 | [UIView commitAnimations]; |
Give Orientation to YES
1 | - ( BOOL )shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
It’s Look Like

Vertical View

Horixontal View
Cheers!!!
No comments:
Post a Comment