2011-10-07 105 views
2

我想插入一個超鏈接,因爲我們已經在uiwebview中。由於鏈接顯示爲「閱讀更多」,當用戶點擊它時,它必須重定向到iPhone瀏覽器中的URL(即safari)。如何在UITextView中插入超鏈接?

請不要建議我使用UIwebview代替它。並不建議我

textView.dataDetectorTypes = UIDataDetectorTypeLink;

因爲在第二種方式顯示給用戶的網址,我不想。

給我任何其他建議,以實現這個或任何示例代碼。

回答

0

是否必須是textView?我做了一些類似的文字添加按鈕,背景不可見,並添加動作來點擊Safari瀏覽器,如下所示:

UIButton *hiperlinkButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [hiperlinkButton setTitle:@"your text" forState:UIControlStateNormal]; 
    [hiperlinkButton setTitleColor:[UIColor colorWithRed:204.0/255.0 green:33.0/255.0 blue:0.0/255.0 alpha:1.0] forState:UIControlStateNormal]; 
    [hiperlinkButton setFrame:CGRectMake(yourposition and size)]; 
    [hiperlinkButton.titleLabel setFont:[UIFont systemFontOfSize:15]]; 
    [hiperlinkButton addTarget:self action:@selector(callSafari:) forControlEvents:UIControlEventTouchUpInside]; 
    [contactsView insertSubview:hyperlinkButton aboveSubview:contactsView]; 
+0

呃..什麼是contactOrkut?不應該是hiperlinkbutton?爲什麼這甚至被標記爲正確? –

+0

是的,我忘了改名字了...... – flopes