button添加链接的title显示效果代码

-(void)setLinks

{

    NSString *text = @"Privacy Policy.";

    NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString: text];

    NSRange range = NSMakeRange(0, [attributedText length]);

    [attributedText beginEditing];

    // next make the text appear with an underline

    NSRange underLineRange = range;

    range.length -= 1;

    [attributedText addAttribute: NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSSingleUnderlineStyle] range:underLineRange];

    [attributedText addAttribute:NSFontAttributeName value:PRDefaultFontWithSize(NO, 12) range:range];

    [attributedText addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithDeviceRed:237/255.0 green:187/255.0 blue:112/255.0 alpha:1] range:underLineRange];

    [attributedText addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithDeviceRed:128/255.0 green:128/255.0 blue:128/255.0 alpha:1]range:NSMakeRange([attributedText length]-1, 1)];

    [attributedText endEditing];

    [self.linkBtn setAttributedTitle:attributedText];

    [attributedText addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithDeviceRed:128/255.0 green:128/255.0 blue:128/255.0 alpha:1] range:range];

    [self.linkBtn setAttributedAlternateTitle:attributedText];

    [self.linkBtn setToolTip:@"http://www.cisdem.com/about/privacy-policy.html"];

}

 

 

-(IBAction)privacyPolicyLinks:(id)sender

{

     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.cisdem.com/about/privacy-policy.html"]];

}

转载于:https://www.cnblogs.com/PJXWang/p/5816655.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 您可以将该代码嵌入到HTML中的script标签中,如下所示: ``` <html> <head> <script type="text/javascript"> // 添加代码的地方 </script> </head> <body> </body> </html> ``` 请在标记之间添加代码。 ### 回答2: 要将代码添加到HTML代码中,可以按照以下步骤进行操作: 1. 打开一个文本编辑器,例如记事本或Sublime Text等。 2. 在编辑器中创建一个新的HTML文件,并将其保存为一个具有.html文件扩展名的文件,例如index.html。 3. 在HTML文件的<head>标签内添加以下代码: ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>网页标题</title> </head> <body> ``` 这段代码是HTML文件的基本结构,包含了<head>标签和<body>标签,其中<head>标签用于定义页面的元数据,<body>标签用于定义页面的内容。 4. 在<head>标签中添加样式表的引用,如果有的话。例如: ```html <link rel="stylesheet" href="style.css"> ``` 这段代码会将style.css样式表文件链接到HTML文件中,可以根据需要调整样式表的文件名和路径。 5. 在<body>标签中添加所需的HTML内容,例如页面的标题、段落、图片等。根据需要将代码添加到合适的位置。 6. 如果上面提到的代码是JavaScript代码,可以通过以下代码将其添加到HTML文件中: ``` <script src="script.js"></script> ``` 这段代码将script.js文件链接到HTML文件中,可以根据需要调整脚本文件的文件名和路径。 7. 在HTML文件的末尾添加以下结尾标签: ```html </body> </html> ``` 这样就完成了代码添加。可以保存HTML文件,并在浏览器中打开以查看结果。 ### 回答3: 将代码添加到HTML中,可以使用以下几种方式: 1. 内联方式: 在HTML文件的 <head> 或 <body> 标签中直接添加代码。例如: ``` <!DOCTYPE html> <html> <head> <title>示例</title> <script> // 这里添加你的代码 </script> </head> <body> <!-- 这里添加其他HTML内容 --> </body> </html> ``` 2. 外部文件引入方式: 将代码保存为一个独立的JavaScript文件,然后通过 <script> 标签引入。在HTML文件的 <head> 或 <body> 标签中添加以下代码: ``` <!DOCTYPE html> <html> <head> <title>示例</title> <script src="your_script.js"></script> </head> <body> <!-- 这里添加其他HTML内容 --> </body> </html> ``` 其中 "your_script.js" 为你保存的JavaScript文件路径。 3. 事件绑定方式: 如果你的代码需要在特定的事件触发时执行,可以将代码放入一个函数中,并通过事件绑定来调用该函数。例如,如果要在按钮点击时执行代码,在HTML文件中添加以下代码: ``` <!DOCTYPE html> <html> <head> <title>示例</title> </head> <body> <button id="myButton">点击我执行代码</button> <script> function myFunction() { // 这里添加你的代码 } document.getElementById("myButton").addEventListener("click", myFunction); </script> </body> </html> ``` 当按钮被点击时,代码将执行 myFunction() 函数内的内容。 以上是常用的几种将代码添加到HTML的方式,你可以根据自己的需求选择其中一种。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值