2012-07-30 19 views
0

在我的應用程序中,我有4個值0,10,20和30.每個值都包含diff url。 我用UITextView來觸發用戶點擊它時的url,但對於值20我需要一個詞應該存在,而不是直接的網址。 現在用戶將點擊該單詞,它應該連接到該值爲20的網址。總之,我想要一個單詞被連接到某個網址。 任何想法???如何在iPhone中將超鏈接設爲單詞?

這裏是我的代碼:

NSString *dot=[NSString stringWithFormat:@"%@",addressInfo.category]; 
NSString *[email protected]"20"; 
if ([dot isEqualToString:dotstr]) { 
urlblue.text = @"eBrochure"; 
    self.urlblue.dataDetectorTypes = UIDataDetectorTypeLink; 

} 

每當用戶點擊 「電子手冊」,我的應用程序應該打開相關的URL .....?

+0

你可以使用一個UIWebView用於這一目的.. – Leena 2012-07-30 09:10:00

+0

但我的Leena需要在TextField中使用它僅 – khadar 2012-07-30 09:20:11

回答

1

是的,你可以使用UIWebView來做到這一點。但如果你只是想使用Textfield,我認爲鏈接可以幫助你。

Tappable URLs in Core Text

^-^

0

您可以使用此代碼繪製:

CGRect underlineFrame = CGRectMake(textLabel.frame.origin.x, textLabel.frame.origin.y+textLabel.frame.size.height, textLabel.frame.size.width, 1); 
UIView *viewUnderline=[[UIView alloc] init]; 
viewUnderline.frame=underlineFrame; 
viewUnderline.backgroundColor=[UIColor blackColor]; 
[self addSubview:viewUnderline]; 
相關問題