2015-12-03 33 views
3

我需要在我的iOS应用程序(在Objective C中)中有一个文本部分,并写入不同的名称。每个姓名必须是链接与个人的信息查看。UIView(或UILabel?)带有链接到故事板中另一个视图

我不知道该怎么做,用什么方法能够在一个文本中生成多个链接,并且链接每个名字都做正确的动作。所以当我点击链接时,它应该将我点击的名称发送到所需的操作。

任何人都知道如何用UIViews做到这一点?还是UILabels?或任何..

此外,每当我把我的视图UIView,加载需要更长的时间,你知道为什么吗?

谢谢..希望已经够清楚了!

HermyKa

+3

只要你选择一个UIButton,将titleLabel设置为名称,然后将动作设置为任何你想要的。 – Jonathan

回答

1

您可以使用RTLabel为,

在代码中添加该库比按照此步骤,

在.h文件中添加以下代码

//Import RTLabel 
#import "RTLabel.h" 
// Add delegate 
@interface ViewController : UIViewController<RTLabelDelegate> 
@end 

而且在.m文件

- (void)viewDidLoad { 
    RTLabel *label = [[RTLabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-262)/2, (self.view.frame.size.height-203)/2, 262, 203)]; 
    label.delegate = self; 

    // You have to create link for each name 
    NSString *searchString = @"<a href=\"Dilip\">Dilip</a> <a href=\"Dev\">Dev</a> <a href=\"Ram\">Ram</a>"; 
} 

//RTLabel Delegate Method 
- (void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSURL*)url 
{ 
    //When user click on one of the name this method will called and url will return the name which user has tapped. You can add condition on name that which view will display. 
    NSLog(@"did tap on name %@", url); 
} 
+0

请不要发布繁重的工作,你可以做本土UIElements的东西。 –

+0

@ Mr.T这是助手网站,我们可以提供任何可以工作的解决方案,其用户可以选择他应该使用哪种东西。也没有什么是沉重的工作,它永远在我们身上。 – Dilip

+0

@ Mr.T这是不正确的理由downvote回答 – Dilip

相关问题