繁体   English   中英

UIView(或UILabel?)链接到故事板中的另一个View

[英]UIView (or UILabel ?) with links to another View in the storyboard

我需要在iOS应用程序中使用文本部分(在Objective C中),并写入不同的名称。 每个名称都必须链接到包含此人信息的视图。

我不知道如何做到这一点,使用什么来在一个文本中生成多个链接,并链接每个名称做正确的操作。 因此,当我点击链接时,它应该将我点击的名称发送到所需的操作。

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

此外,每当我在我的视图中放置UIView时,加载时间会更长,你知道为什么吗?

谢谢..希望足够清楚!

HermyKa

您可以使用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);
}

您可以使用连接到每个的手势识别器的UILabels集。 或者是一组UIButtons。 http://www.raywenderlich.com/104744/uigesturerecognizer-tutorial-creating-custom-recognizers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM