1

I am using CoverFlow in my application ,it is working fine but, I need to display the title of image that appears to front in coverflow,To add images iam usinf following code...

loadImagesOperationQueue = [[NSOperationQueue alloc] init];
 for (int i=0; i < 10; i++) 
        {
        imageName = [[NSString alloc] initWithFormat:@"cover_%d.jpg", i];
        [(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:imageName] forIndex:i];
          NSLog(@"my image name is %@",imageName);
        NSLog(@"%d is the index",i);

        }

        [(AFOpenFlowView *)self.view setNumberOfImages:10];

Can any one help me out.Below is the screenshot I would like to implement.

 ]![enter image description here

Youngwing
  • 577
  • 2
  • 6
  • 24
  • label=[[UILabel alloc]initWithFrame:CGRectMake(0, 280, 145, 50)]; label.opaque=YES; label.hidden=YES; label.textColor=[UIColor whiteColor]; label.backgroundColor=[UIColor clearColor]; label.font=[UIFont boldSystemFontOfSize:20]; label.textAlignment=UITextAlignmentCenter; [self addSubview:label]; do this in AFItemView class in - (id)initWithFrame:(CGRect)frame class – Rama Rao Feb 16 '12 at 09:36
  • I have done with the lable, my app is crashing at [coverImageName setObject:coverView.imageName forKey:coverNumber];with crash report , '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: 0)' – Youngwing Feb 16 '12 at 09:42
  • arey yar u have to pass the image name from the CoverFlowViewController class na?see below answer.U have to change the method name as - (void)setImage:(UIImage *)image forIndex:(int)index named:(NSString*)imageName; from - (void)setImage:(UIImage *)image forIndex:(int)index; in AFOpenFlowView class. – Rama Rao Feb 16 '12 at 09:47
  • Thanks alot!!! it is working!! I changed - (void)setImage:(UIImage *)image forIndex:(int)index to - (void)setImage:(UIImage *)image forIndex:(int)index named:(NSString *)imageName.... – Youngwing Feb 16 '12 at 09:58
  • @hai.what happen to your gmail? – Youngwing Apr 12 '12 at 07:25
  • its there but I am using less.Use webview to get the javascript data – Rama Rao Apr 12 '12 at 07:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/9989/discussion-between-developer-and-rama-rao) – Youngwing Apr 12 '12 at 07:37

2 Answers2

3

You simply take a label in method- (id)initWithFrame:(CGRect)frame{} for class AFItemView.m in openflow code and check in the class:AFOpenFlowView.m in method - (void)centerOnSelectedCover:(BOOL)animated{} set text as belowselectedCoverView.label.text=coverImagename;.This worked for me.

Rama Rao
  • 1,043
  • 5
  • 22
  • Can I know what is coverImagename here? same as my imageName? I have declared property for imageName in my CoverFlowViewController class,but it is nor appearing in AFOpenFlowView.m. – Youngwing Feb 16 '12 at 07:41
  • @Rama Rao - (void)centerOnSelectedCover:(BOOL)animated { CGPoint selectedOffset = CGPointMake(COVER_SPACING * selectedCoverView.number, 0); coverView=[[CoverFlowViewController alloc]init]; selectedCoverView.lbl.text=coverView.imageName; NSLog(@" here image name is %@",selectedCoverView.lbl.text); [scrollView setContentOffset:selectedOffset animated:animated]; } the log is showing null value,title is not added to image. – Youngwing Feb 16 '12 at 07:52
  • check the below code:- (void)centerOnSelectedCover:(BOOL)animated { CGPoint selectedOffset = CGPointMake(COVER_SPACING * selectedCoverView.number, 0); NSNumber *coverNumber = [NSNumber numberWithInt:selectedCoverView.number]; NSString *coverImagename=[coverImageName objectForKey:coverNumber]; selectedCoverView.label.text=coverImagename; selectedCoverView.label.hidden=NO; [scrollView setContentOffset:selectedOffset animated:animated]; } – Rama Rao Feb 16 '12 at 07:53
  • Sorry I didn't get this line, NSString *coverImagename=[coverImageName objectForKey:coverNumber];is coverImageName dictionary? – Youngwing Feb 16 '12 at 08:42
3

yes.U have to pass like below:`

- (void)setImage:(UIImage *)image forIndex:(int)index named:(NSString*)imageName{
    // Create a reflection for this image.
    UIImage *imageWithReflection = [image addImageReflection:kReflectionFraction];
    NSNumber *coverNumber = [NSNumber numberWithInt:index];
    [coverImages setObject:imageWithReflection forKey:coverNumber];
    [coverImageHeights setObject:[NSNumber numberWithFloat:image.size.height] forKey:coverNumber];
    [coverImageName setObject:imageName forKey:coverNumber];`

    // If this cover is onscreen, set its image and call layoutCover.
    AFItemView *aCover = (AFItemView *)[onscreenCovers objectForKey:[NSNumber numberWithInt:index]];
    if (aCover) {
        [aCover setImage:imageWithReflection originalImageHeight:image.size.height reflectionFraction:kReflectionFraction named:imageName];

        [self layoutCover:aCover selectedCover:selectedCoverView.number animated:NO];
    }
}`

and i pass the image name like below:

for (int i=0; i < 10; i++) {
        imageName = [[NSString alloc] initWithFormat:@"cover_%d.jpg", i];UIImage* image_=[UIImage imageNamed:imageName];
        CGFloat width = 290;
        CGFloat height = 200;

        CGSize newSize=CGSizeMake(width, height);
        [(AFOpenFlowView *)self.view setImage:[self imageWithImage:image_ scaledToSize:newSize] forIndex:i named:imageName];
        [imageName release];
        NSLog(@"%d is the index",i);

    }
    [(AFOpenFlowView *)self.view setNumberOfImages:10];
Rama Rao
  • 1,043
  • 5
  • 22