All pastes #2049355 Raw Edit

Something

public text v1 · immutable
#2049355 ·published 2011-04-22 12:15 UTC
rendered paste body
-(void)openFlowView:(AFOpenFlowView *)openFlowView selectionDidChange:(int)index
{
    currentItem = index;
    
    for (UILabel * label in textLabels)
    {
        [label removeFromSuperview];
        [label release];
    }
    
    [textLabels release];
    textLabels = nil;
    
    UIImage *myImage = [UIImage imageNamed:[NSString stringWithFormat:@"preview_premium_%d.png", index+1]];
    
//    CGSize imageSize = myImage.size;
    if (myImage.size.height > 350)
        myImage = [NSHelper imageWithImage:myImage scaledToHeight:350];
    else if (myImage.size.height < 200)
        myImage = [NSHelper imageWithImage:myImage scaledToFixedHeight:floor(myImage.size.height * 1.5)];
    
    if (myImage.size.width > 310)
        myImage = [NSHelper imageWithImage:myImage scaleToWidth:310];
    else if (myImage.size.height < 250 && myImage.size.width < 200)
        myImage = [NSHelper imageWithImage:myImage scaledToFixedHeight:floor(myImage.size.height * 1.5)];        
    
    
    CGRect imageFrame = normalRect;
    imageFrame.size.height = myImage.size.height;
    imageFrame.origin.x += (imageFrame.size.width - myImage.size.width);
    if (index == 2)
        imageFrame.origin.x -= 40;
    imageFrame.size.width = myImage.size.width;
    
    UIImageView * newImageView = [[UIImageView alloc] initWithFrame:imageFrame];
    newImageView.image = myImage;
    newImageView.alpha = 0;
   // newImageView.contentMode = UIViewContentModeScaleToFill;
    newImageView.layer.shadowOffset = CGSizeMake(4,4);
    newImageView.layer.shadowOpacity = 0.7f;
    newImageView.layer.shadowRadius = 5.0;
    [self.view addSubview:newImageView];
    
    [UIView animateWithDuration: 0.15
						  delay: 0
						options: UIViewAnimationCurveLinear
					 animations: ^{ selectedImage.alpha = 0; }
					 completion: ^(BOOL finished) 
                                {[UIView animateWithDuration: 0.15
                                                       delay: 0
                                                     options: UIViewAnimationCurveLinear
                                                  animations: ^{ newImageView.alpha = 1; }
                                                  completion: ^(BOOL finished) 
                                  {[selectedImage removeFromSuperview];
                                   [selectedImage release];
                                   selectedImage = newImageView;} ];}];
    
    //[selectedImage removeFromSuperview];
    //[selectedImage release];
    
    
    
    
    
    
    /*selectedImage.frame = CGRectMake(normalRect.origin.x, 
                                     normalRect.origin.y
                                     + (normalRect.size.height - myImage.size.height) / 2.0, 
                                     myImage.size.width,
                                     myImage.size.height);*/
    
    NSDictionary * infoList = [textList objectAtIndex:index];
    
    //int height = floorf(textView.frame.size.height);
    //int width = floorf(textView.frame.size.width);
    
    //- 78
    CGRect frame = CGRectMake(0, 35, textViewSize.width - 55, 65);
    
    textLabels = [[NSMutableArray alloc] initWithObjects:nil];
    
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    BOOL isPortrait = (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown);    
    
    if (!isPortrait){
        textViewSize.height = 401;
        textViewSize.width = 504;        
    }
    
    // adding title text
    CGRect titleFrame = frame;
    titleFrame.size.width += 10.0;
    NSString *titleText = [infoList objectForKey:@"TitleKey"];
    titleText = [titleText stringByReplacingOccurrencesOfString:@"r det bedste" 
                                                     withString:(isPortrait?@"r\ndet bedste":@"r det bedste")];
    titleText = [titleText stringByReplacingOccurrencesOfString:@" end en pris" 
                                                     withString:(isPortrait?@"\nend en pris":@" end en pris")];
    
    titleFrame.size = [titleText sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:18] 
                            constrainedToSize:titleFrame.size];
    
    frame.origin.y = floor(frame.origin.y + titleFrame.size.height + textViewSize.height / 14);
    
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:titleFrame];
    
    
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.numberOfLines = 0;
    titleLabel.text = titleText;
    
    [textView addSubview:titleLabel];
    [textLabels addObject:titleLabel];
    
    //adding list text
    
    wasItem = NO;
    wasSmallItem = NO;
    
    NSArray * list = [infoList objectForKey:@"ItemKey"];
    frame.origin.x = frame.origin.x + 20;
    
    [textsForLabels release];
    textsForLabels = [[NSMutableArray alloc] init];
    NSInteger currentTag = 0;
    
    for ( id item in list )
    {
        if ( [item isKindOfClass:[NSString class]])
        {
            if ( wasSmallItem )
            {
                frame.origin.y = floor(frame.origin.y + textViewSize.height / 31);
            }
            
            NSString *itemText = [item stringByReplacingOccurrencesOfString:@"\n" 
                                                                 withString:(isPortrait?@"\n":@" ")];
            
            
            CGSize labelSize = [itemText sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:BIG_TEXT_SIZE] constrainedToSize:frame.size];
            CGRect labelFrame = CGRectMake(frame.origin.x, frame.origin.y, labelSize.width, labelSize.height);
            
            UILabel * label = [[UILabel alloc] initWithFrame:labelFrame];
            label.text = itemText;
            label.textColor = [UIColor whiteColor];
            label.font = [UIFont fontWithName:@"Helvetica-Bold" size:BIG_TEXT_SIZE];
            label.backgroundColor = [UIColor clearColor];
            label.numberOfLines = 0;
            label.tag = currentTag;
            
            [textsForLabels insertObject:item atIndex:currentTag];
            currentTag++;
            
            frame.origin.y = floor(frame.origin.y + labelSize.height + textViewSize.height / 20);
            
            //adding star images
            UIImageView * starView = [[UIImageView alloc] initWithFrame:CGRectMake(labelFrame.origin.x - 21, labelFrame.origin.y + 4, 9, 9)];
            starView.image = [UIImage imageNamed:@"Star_NEG.png"];
            
            [textView addSubview:label];
            [textLabels addObject:label];
            
            [textView addSubview:starView];
            [textLabels addObject:starView];
            
            wasItem = YES;
            wasSmallItem = NO;
        }
        
        //adding sublist text
        if ( [item isKindOfClass:[NSArray class]])
        {
            frame.origin.x = frame.origin.x + 16;
            
            if ( wasItem )
            {
                frame.origin.y = floor(frame.origin.y - textViewSize.height / 31);
            }
            
            for ( id smallItem in item )
            {
                NSString *smallItemText = [smallItem stringByReplacingOccurrencesOfString:@"\n" 
                                                                          withString:(isPortrait?@"\n":@" ")];
                
                CGSize labelSize = [smallItemText sizeWithFont:[UIFont fontWithName:@"Helvetica" size:SMALL_TEXT_SIZE] constrainedToSize:frame.size];
                CGRect labelFrame = CGRectMake(frame.origin.x, frame.origin.y, labelSize.width, labelSize.height);
                
                UILabel * label = [[UILabel alloc] initWithFrame:labelFrame];

                label.text = smallItemText;
                label.textColor = [UIColor whiteColor];
                label.font = [UIFont fontWithName:@"Helvetica" size:SMALL_TEXT_SIZE];
                label.backgroundColor = [UIColor clearColor];
                label.numberOfLines = 0;
                label.tag = currentTag;
                
                [textsForLabels insertObject:smallItem atIndex:currentTag];
                currentTag++;
                
                frame.origin.y = floor(frame.origin.y + labelSize.height + textViewSize.height / 56);
                
                //adding dot images
                UIImageView * dotView = [[UIImageView alloc] initWithFrame:CGRectMake(labelFrame.origin.x - 17, labelFrame.origin.y + 4, 9, 9)];
                dotView.image = [UIImage imageNamed:@"Bull_NEG.png"];
                
                [textView addSubview:label];
                [textLabels addObject:label];
                
                [textView addSubview:dotView];
                [textLabels addObject:dotView];
                
                wasItem = NO;
                wasSmallItem = YES;
            }
            
            frame.origin.x = frame.origin.x - 16;
        }
    }
    slideshowButton.frame = selectedImage.frame;
}