NSString
“在这里获取xxx iPhone应用程序”。在此字符串“Here”中,我想将hyperlink
提供给特定的URL
。它用于FB Share,我正在使用UIActivityViewController
。我不想去UILabel
。我知道这可能很愚蠢......帮助我。
先谢谢Geeks ....
答案 0 :(得分:0)
如果此版本的IOS 6或更高版本的应用程序可以使用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];
见下图
答案 1 :(得分: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];