0

我有什么办法可以做到,所以当用户单击 TTStyledLabel 中的图像时,它会在three20的图像查看器中打开?

4

1 回答 1

1

基本上是的。由于 TTStyledText 可以包含 html 标签,因此您可以利用three20 导航来发挥您的优势,您所要做的就是用标签包装img 标签,并为从three20 的照片查看器派生的控制器设置您自己的映射。

NSString* kText = @"This is a test of styled labels. <a href=\"yourapp://photo/http%3A%2F%2Fsomeserver.com%2Fsmiley.png\"><img src=\"http://someserver.com/smiley.png\"/</a>";
TTStyledTextLabel* label1 = [[[TTStyledTextLabel alloc] init] autorelease];
label1.text = [TTStyledText textFromXHTML:kText lineBreaks:YES URLs:YES];

在您的应用程序委托中,您的控制器有一个映射,如下所示:

TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
[map from:@"yourapp://photoViewer/(initWithPhotoUrl:)" toViewController:[TTWebController class]];

照片视图控制器应该有这个初始化方法:

-(id)initWithPhotoUrl:(NSString*)photoURL {
    self = [self initWithNibName:nil bundle:nil];
    if (self) {
        NSString *unencodedURL = [photoURL gtm_stringByUnescapingFromURLArgument];//this is where you decode the string (notice we encode it in the html). Google toolbox has a nice category for Strings to encode and decode urls see: http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMNSString%2BURLArguments.h?r=373
    }
    return self;
}

在 initWithPhotoUrl: 中,您需要创建一个照片源 - 请参阅 TTCatalog 示例以获取有关如何创建 MockPhotoSource 的示例。

于 2011-12-28T09:28:16.333 回答