首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone/Objective-C TTLauncherView从URL加载高分辨率图像

iPhone/Objective-C TTLauncherView从URL加载高分辨率图像
EN

Stack Overflow用户
提问于 2011-03-21 13:18:26
回答 2查看 1.3K关注 0票数 0

我正在使用Three20的TTLauncherView,我想知道是否有人有过加载高分辨率图像的经验?

http://three20.info/showcase/launcher

我正在使用以下方法来设置我的TTLauncherItem

代码语言:javascript
复制
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];

这是我用来确定它是否是iOS4的方法。

代码语言:javascript
复制
- (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;
}

问题是,图像实际上是在iPhone 4上以全尺寸显示,而iPhone 4以下的任何iOS设备都能正常显示。我想知道我是否需要对TTLauncherView库进行更改,或者是否有更简单的方法来解决这样的问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-03-22 18:29:19

为此,我在基于launcherButtonImage的three20样式表中添加了一个新样式。这是原始的..。

代码语言:javascript
复制
     - (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这是更新后的版本...

代码语言:javascript
复制
- (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;
}

里面可能有一些你不需要的东西,比如圆角图像。执行部分是TTImageStyle指令,它将图像大小锁定为64x64。希望这能有所帮助。

票数 2
EN

Stack Overflow用户

发布于 2011-03-21 13:26:29

我使用的是Three20的TTLauncherView

相反,尝试使用SDWebImage:

https://github.com/rs/SDWebImage

您可以在UIImageView上执行两个加载,一个用于高分辨率图像,另一个用于低分辨率图像。低分辨率的应该第一个完成...

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5374091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档