【发布时间】:2011-12-26 23:59:49
【问题描述】:
我有什么办法可以做到,当用户单击 TTStyledLabel 中的图像时,它会在three20 的图像查看器中打开?
【问题讨论】:
标签: ios three20 ttstyledtextlabel
我有什么办法可以做到,当用户单击 TTStyledLabel 中的图像时,它会在three20 的图像查看器中打开?
【问题讨论】:
标签: ios three20 ttstyledtextlabel
基本上是的。由于 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 的示例。
【讨论】: