1

NSString“在此处获取 xxx iPhone 应用程序”。在这个字符串 "Here" 中,我想给hyperlink特定URL的 . 它用于 FB Share ,我正在使用UIActivityViewController. 我不想去UILabel。我知道这可能很愚蠢,...帮帮我。

提前感谢极客....

4

2 回答 2

0

如果您想在 Facebook 上分享,您需要告诉 Safari 打开一个 URL,该 URL 将显示一个允许用户分享的 Facebook 页面。这是一个例子:

//The url you want to share
NSString *urlString = @"http://stackoverflow.com";

//The title you want to be displayed on Facebook
NSString *title = "The Title of the Page";

//Create the URL string which will tell Facebook you want to share that specific page 
NSString *shareUrlString = [NSString stringWithFormat:@"http://www.facebook.com/sharer.php?u=%@&t=%@", urlString , title];

//Create the URL object 
NSURL *url = [ [ NSURL alloc ] initWithString:shareUrlString ];

//Launch Safari with the URL you created        
[[UIApplication sharedApplication] openURL:url];

//Release the object if you don't need it
[url release];
于 2013-05-22T11:32:49.370 回答
0

如果这个应用程序适用于 IOS6 或更高版本,那么您可以NSMutableAttributedString这样使用。并根据Here字符串设置自定义按钮的框架。

 NSString *infoString=@"Get the Solestruck iPhone App Here";

        NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:infoString];
        NSInteger _stringLength=[infoString length];

        // ------------------ Give your range for underline
        [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(_stringLength-4, 4)];

        lbl.attributedText = attString;

        [lbl setBackgroundColor:[UIColor clearColor]];

        // ---------------- Give frame according to your text -------
//-------------------- Small change in below two line ------------
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(lbl.frame.size.width-50, 0,50, lbl.frame.size.height);
        [btn setBackgroundColor:[UIColor redColor]];

        [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];

        [lbl addSubview:btn];

        [lbl setUserInteractionEnabled:YES];

见下图

在此处输入图像描述

于 2013-05-22T11:19:29.080 回答