gpt4 book ai didi

iPhone:- 从标签文本中识别链接

转载 作者:搜寻专家 更新时间:2023-10-30 20:10:07 26 4
gpt4 key购买 nike

在我的 iPhone 应用程序中,我想以不同的颜色显示标签内的链接(如超链接)。

当有人点击链接时,它应该在 Safari 浏览器中打开链接。

我该怎么做?

最佳答案

听到下面是两个示例示例代码链接,希望对您有所帮助:-

https://github.com/twotoasters/TTTAttributedLabel

http://furbo.org/stuff/FancyLabel_1.0.zip

或者你也可以这样做

将标签的 userInteractionEnabled 设置为 YES 并向其添加手势识别器:

myLabel.userInteractionEnabled = YES;

UITapGestureRecognizer *gestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openUrl:)];
gestureRec.numberOfTouchesRequired = 1;
gestureRec.numberOfTapsRequired = 1;
[myLabel addGestureRecognizer:gestureRec];
[gestureRec release];

Then implement the action method:

- (void)openUrl:(id)sender
{
UIGestureRecognizer *rec = (UIGestureRecognizer *)sender;

id hitLabel = [self.view hitTest:[rec locationInView:self.view] withEvent:UIEventTypeTouches];

if ([hitLabel isKindOfClass:[UILabel class]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:((UILabel *)hitLabel).text]];
}
}

关于iPhone:- 从标签文本中识别链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13965989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com