2010-02-16 24 views
2

嗨,我創建了一個TTStyledTextLabel,效果很好。TTStyledText中的URL和圖像

現在我想使URL點擊,我已經做到了這一點:

textLabel.text = [TTStyledText textFromXHTML:[content objectForKey:@"content"] lineBreaks:YES URLs:YES]; 

,但我的鏈接仍然無法點擊。我必須先設置一個UIWebView嗎?在哪裏申報?

另一件事是,是否可以調整我的TTStyledTextLabel中的圖片大小以適應他們的標籤大小?

在此先感謝

//編輯

什麼我有完全做到:

textLabel = [[TTStyledTextLabel alloc] initWithFrame:CGRectMake(0.0f, 70.0f, 320.0f, 297.0f)]; 
textLabel.contentInset = UIEdgeInsetsMake(20, 15, 20, 15); 
textLabel.font = [UIFont systemFontOfSize:14]; 
textLabel.text = [TTStyledText textFromXHTML:[content objectForKey:@"content"] lineBreaks:YES URLs:YES]; 
[textLabel sizeToFit]; 
//CGFloat height = textLabel.height; 
[scrollView addSubview:textLabel]; 
scrollView.contentSize = textLabel.frame.size; 

一個的NSLog我[content objectForKey:@"content"]回報是這樣的:

<a href="http://www.abc.com/">Download-Link</a> 

我的鏈接在我的標籤中突出顯示,但它們無法點擊。

我初始化我爲textLabel在- (void)viewDidLoad在一個UIViewController

+0

沒人?我必須寫的任何事情,我的文字是更好理解? – choise 2010-02-17 10:55:54

回答

4
the [content objectForKey:@"content"] should return data containing <a href="url">string to display</a> 

如果你添加的網址TTURLMap它也將打開相關的控制器

下面的代碼片段應該工作

self = [super init]; 
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] initWithFrame:CGRectMake(0, 0, 320, 230)] autorelease]; 
label.text = [TTStyledText textFromXHTML:@"<a href=\"aa://link1\">link</a> text" lineBreaks:YES URLs:YES]; 
[label setFont:[UIFont systemFontOfSize:16]]; 
[[self view] addSubview:label]; 

//編輯

所以你可能需要在URLMap地圖「*」,如果你使用的是TTNavigator,是這樣的:

TTNavigator* navigator = [TTNavigator navigator]; 

navigator.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[navigator.window makeKeyAndVisible]; 

TTURLMap* map = navigator.URLMap; 
[map from:@"*" toViewController:[TTWebController class]]; 

這將映射所有的URL到TTWebController這將打開一個網頁視圖的在

+0

這就是我所做的,檢查我的第一篇文章的編輯。 – choise 2010-02-17 18:02:17

+0

沒問題,所以我意識到我必須初始化一個TTNavigator和一個TTURLMap。我做了這個,我的鏈接現在正在工作。但是當我在TTWebController中時,我不能後退。有沒有什麼訣竅可以回到我的當前導航控制器上? – choise 2010-02-17 18:27:27

+0

我有同樣的問題,但是我發現我已經試過這樣做,這導致了問題,不幸的是我不記得我已經做了什麼。它應該工作的框,所以嘗試刪除不必要的代碼,我會盡力記住我已經完成 – 2010-02-17 18:38:50

0

我瀏覽同樣的問題。嘗試使用

[navigator setRootViewController:"your main controller";] 

這對我很有用。