0

I am using Three20's TTLauncherView and was wondering whether anyone has had experience loading high resolution images?

http://three20.info/showcase/launcher

I am using the following method to set my TTLauncherItem's:

NSString *imageUrl = [self displayImageUrl:@"http://foo.com/lowres.png" withHighResUrl:@"http://foo.com/hires.png";
TTLauncherItem *launcherItem = [[[TTLauncherItem alloc] initWithTitle:@"Icon1"
                                                                image:imageUrl
                                                                  URL:@"Icon1"
                                                            canDelete:NO] autorelease];

This is the method I use to determine whether it's an iOS4.

- (NSString *)displayImageUrl:(NSString *)standardResUrl withHighResUrl:(NSString *)highResUrl {
    NSString *imageUrl = nil;
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2) {
        imageUrl = highResUrl;
    } else {
        imageUrl = standardResUrl;
    }

    return imageUrl;
}

The problem is that images are actually getting displayed in their full dimensions on an iPhone 4, whereas any iOS device below an iPhone 4 are getting displayed properly. Just wondering whether I would need to make changes to the TTLauncherView library or whether there's an easier way to resolve such an issue.

gotnull
  • 26,454
  • 22
  • 137
  • 203

2 Answers2

2

I accomplished this by adding a new style to my three20 stylesheet based on launcherButtonImage. This is the original...

     - (TTStyle*)launcherButtonImage:(UIControlState)state {
      TTStyle* style =
        [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(-7, 0, 11, 0) next:
        [TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:8] next:
        [TTImageStyle styleWithImageURL:nil defaultImage:nil contentMode:UIViewContentModeCenter
                      size:CGSizeZero next:nil]]];

      if (state == UIControlStateHighlighted || state == UIControlStateSelected) {
          [style addStyle:
            [TTBlendStyle styleWithBlend:kCGBlendModeSourceAtop next:
            [TTSolidFillStyle styleWithColor:RGBACOLOR(0,0,0,0.5) next:nil]]];
      }

  return style;
}

...and this is the updated version...

- (TTStyle*)favoriteLauncherButtonImage:(UIControlState)state {

    TTStyle* style =
    [TTShapeStyle styleWithShape:[TTRoundedRectangleShape
                                  shapeWithRadius:4.0] next:
     [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(0, 0, 0, 0)
                         padding:UIEdgeInsetsMake(16, 16, 16, 16)
                         minSize:CGSizeMake(0, 0)
                        position:TTPositionStatic next:
      [TTImageStyle styleWithImageURL:nil defaultImage:nil contentMode:UIViewContentModeScaleAspectFit
                                 size:CGSizeMake(64, 64) next: nil
       ]]];

    if (state == UIControlStateHighlighted || state == UIControlStateSelected) {
        [style addStyle:
         [TTBlendStyle styleWithBlend:kCGBlendModeSourceAtop next:
          [TTSolidFillStyle styleWithColor:RGBACOLOR(0,0,0,0.5) next:nil]]];
    }

    return style;
}

There's probably stuff in there you don't need like rounded image corners. The operative part is the TTImageStyle directive which locks the image size to 64x64. Hope this helps.

Kirby Todd
  • 11,254
  • 3
  • 32
  • 60
1

I am using Three20's TTLauncherView

Instead, try using SDWebImage:

https://github.com/rs/SDWebImage

You could just issue two loads on a UIImageView, one for the high and one for the low res image. The low-res should finish first...

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • Thanks for this, the problem is not loading/caching images. It's that the TTLauncherView doesn't have a facility for loading high resolution images as far as I know? – gotnull Mar 21 '11 at 05:31
  • 1
    The very fact you are using ThreeTwenty is inherently a problem, if you are even considering making changes to it it means you need to move to something else, even if you have to change it to do what you want also. ThreeTwenty was the very first of the frameworks, was not well written, and most aspects of it have been superseded by better frameworks to take up where it left off. – Kendall Helmstetter Gelner Mar 21 '11 at 06:04
  • SOrry, don't understand what you meant by the last question. The way I generally use SDWebImage is a local placeholder, and a URL that loads in the background a high-res image. I usually have a UIImageView set to scaleAspectFit, so if the image is larger it will look good on both Retina and non-retina displays (and the iPad kind of acts like a retina for running iPhone apps at 2x size) – Kendall Helmstetter Gelner Mar 21 '11 at 07:18
  • Okay, so not really related to what I'm trying to do with TTLauncherView then. Appreciate your help though. – gotnull Mar 21 '11 at 12:12