以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)

我必须确保我可以点击“隐私”一词来打开网页链接。 我尝试了我发现的建议,但他们都是旧事物,他们似乎不再工作了......我不知道我该如何解决问题

    private lazy var firstTermDescriptionLabel: UILabel = {
    let label = UILabel(frame: .zero)
    let firstTermsMessage = "I Agree to the License Terms and Privacy Policy"
    var attributedString = NSMutableAttributedString.init(string: "Privacy")
    attributedString.addAttribute(.link, value: "https://www.google.com/url?q=https://www.iubenda.com/privacy-policy/58446596&sa=D&source=hangouts&ust=1528787597335000&usg=AFQjCNEPkofPxSm7TDRMvxjOjCz5cio27w", range: NSRange(location: 0, length: 7))

    label.isUserInteractionEnabled = true
    label.text = firstTermsMessage
    label.font = UIFont.systemFont(ofSize: 13, weight: .regular)
    label.textAlignment = .left
    label.numberOfLines = 0
    label.translatesAutoresizingMaskIntoConstraints = false
    label.heightAnchor.constraint(equalToConstant: 36).isActive = true
    return label
}()

那是结果


I have to make sure that I can click on the word "Privacy" in order to open a web link. I tried with the suggestions that I found but they are old things and they do not seem to work anymore .. I do not know how I can solve the problem

    private lazy var firstTermDescriptionLabel: UILabel = {
    let label = UILabel(frame: .zero)
    let firstTermsMessage = "I Agree to the License Terms and Privacy Policy"
    var attributedString = NSMutableAttributedString.init(string: "Privacy")
    attributedString.addAttribute(.link, value: "https://www.google.com/url?q=https://www.iubenda.com/privacy-policy/58446596&sa=D&source=hangouts&ust=1528787597335000&usg=AFQjCNEPkofPxSm7TDRMvxjOjCz5cio27w", range: NSRange(location: 0, length: 7))

    label.isUserInteractionEnabled = true
    label.text = firstTermsMessage
    label.font = UIFont.systemFont(ofSize: 13, weight: .regular)
    label.textAlignment = .left
    label.numberOfLines = 0
    label.translatesAutoresizingMaskIntoConstraints = false
    label.heightAnchor.constraint(equalToConstant: 36).isActive = true
    return label
}()

enter image description here


原文:https://stackoverflow.com/questions/50793833
2024-04-25 16:04

满意答案

EXCEPTION子句需要与异常处于同一个块中。

例如:

CREATE OR REPLACE FUNCTION test_excep (arg integer)
  RETURNS integer
AS
$func$
DECLARE
   res INTEGER;
BEGIN

res := 100 / arg;

RETURN res;

EXCEPTION
    WHEN division_by_zero 
    THEN  RETURN 999;

END
$func$
LANGUAGE plpgsql;

The EXCEPTION clause needs to be in the same block as the exception.

For instance:

CREATE OR REPLACE FUNCTION test_excep (arg integer)
  RETURNS integer
AS
$func$
DECLARE
   res INTEGER;
BEGIN

res := 100 / arg;

RETURN res;

EXCEPTION
    WHEN division_by_zero 
    THEN  RETURN 999;

END
$func$
LANGUAGE plpgsql;

相关问答

更多

何时以及如何使用异常处理?(When and how should I use exception handling?)

这是一个非常全面的指导,我认为是必读: 异常和错误处理 - C ++常见问题或C ++常见问题 作为一般的经验法则,当您的程序可以识别出阻止执行的外部问题时,抛出异常。 如果您从服务器接收数据,并且数据无效,则抛出异常。 磁盘空间不足? 抛出异常 宇宙射线阻止您查询数据库? 抛出异常 但是如果您从自己的程序中获取一些无效数据 - 不要抛出异常。 如果你的问题来自你自己的坏代码,最好使用ASSERT来防范它。 需要异常处理来识别程序无法处理的问题,并告诉他们有关用户的问题,因为用户可以处理它们。 但...

我如何让python函数返回异常回溯或结果?(How do I have a python function return an exception traceback, or the result?)

我建议,不要在此方法中捕获异常,而是让它引发异常并从您调用的任何地方捕获它。 换句话说,不要把你的try catch放在那个方法中。 将try catch放在调用该方法的任何地方,并捕获它可以提升的内容。 所以,请改为: import traceback def ReadFile(): with open("/etc/passwd") as file: data = file.read() return data try: r = ReadFile() ...

返回具有异常处理的函数中的类(Returning a class in a function with exception handling)

有几种方法可以解决这个问题。 第一种是更改返回函数的返回类型,而不是通过值返回类,通过std::unique_ptr传递它。 std::unique_ptr可以为null,因此如果有异常,则可以返回null unique_ptr否则只需将unique_ptr返回给您创建的对象。 另一种选择是使用boost::optional或std::optional 。 您现在可以使用boost::optional但std::optional是C ++ 17的功能,因此它的可用性有限。 就个人而言,我更喜欢可选...

Selenium异常:“不返回函数”(Selenium Exception : “return not in a function”)

来自GetEval的selenium文档 : 获取评估指定JavaScript代码段的结果。 代码段可能有多行,但只会返回最后一行的结果。 因此,您只需要return : string code = selenium.GetEval( "var win = this.browserbot.getUserWindow(); "+ "win.editAreaLoader.GetValue(win.loadedCodeEditorID);" ); From the selenium doc...

装饰函数中的异常处理(exception handling in decorator function)

将我的评论转换为答案: 你应该使用像: def retry(function): @wraps(function) def _retry(*args, **kwargs): try: reply = function(*args, **kwargs) print "reply: ", reply return reply except PDError as msg: ...

处理EXCEPTION并从函数返回结果(Handling EXCEPTION and return result from function)

EXCEPTION子句需要与异常处于同一个块中。 例如: CREATE OR REPLACE FUNCTION test_excep (arg integer) RETURNS integer AS $func$ DECLARE res INTEGER; BEGIN res := 100 / arg; RETURN res; EXCEPTION WHEN division_by_zero THEN RETURN 999; END $func$ LANGUAGE...

通过异常处理创建Sybase函数(Create Sybase function with exception handling)

使用TRY_CONVERT而不是CONVERT ,这将是: CREATE FUNCTION TEST(@date varchar(50)) RETURNS DATETIME AS BEGIN RETURN TRY_CONVERT(DATETIME, @date) END 结果: select [dbo].[TEST]('20171201') --output:2017-12-01 00:00:00.000 select [dbo].[TEST]('9999999999') --out...

如果抛出异常,则使extern C ++函数返回消息(Make extern C++ function return a message if an exception is thrown)

让您的函数返回BOOL ,并将错误消息字符串作为参数,例如: BOOL Calculate(double &result, double a, double b, char *pMsg, size_t nMsgSize) { try { result = InternalCalculation(a, b); } catch(std::invalid_argument& e) { strncpy_s(pMsg, nMsgSize, e.what(), _T...

SQL:函数中的异常处理(SQL: exception handling in a function)

这是你应该处理的......我在你的代码中添加了'return -1'。 HTH。 create or replace FUNCTION f_interestrate(pn_principal NUMBER, pn_interest NUMBER, pn_years NUMBER) RETURN NUMBER IS vn_interestrate NUMBER; ex_invalid_devisor EXCEPTION; BEGIN IF pn_pri...

如何在异常之前捕获返回(How to capture return prior to exception)

这似乎有效: function functionWhichCreatesOutputThenCausesAnException() { "hello" 1/0 "world" } try { $result = @() functionWhichCreatesOutputThenCausesAnException | foreach {$result += $_} } catch { $($error[0]) } This seems to w...

相关文章

更多

千锋首发Swift视频教程

千锋Swift视频教程-7.Swift结构体.mp4 千锋Swift视频教程-13.代理反向传值.mp ...

Swift入门视频教程-尚学堂视频教程

最新Swift语言语法介绍,包括Swift流程控制语句、Swift各种构造函数、closure、泛型、 ...

ios label 竖排设置

labelObject.numberOfLines = 0;labelObject.lineBreak ...

学习di'z地址

杨丰盛cocos2d-x教程下载地址:http://www.dwz.cn/gwPgd 无限互联新浪微博 ...

Prince Of Persia III - The Two Thrones 通关完成

"Prince,there still something I don't understa ...

基于Web的打印方案比较分析(三) 使用WScript.Shell通过编程方式进行复杂的WEB打印

 使用WScript.Shell,必须要求客户IE允许 Activex进行交互。如果是你开发的系统是针 ...

java网络编程练习

1、练习--TCP客户端并发登陆/* 客户端通过键盘录入用户名,服务端对这个用户名进行校验。 如果 ...

Hadoop的thrift server配置

说明:Hadoop版本:hadoop-1.2.1.tar.gz。linux系统12.04,不过这里跟系 ...

FreeMarker基本标签的使用

上一节我们接触了一个FreeMarker很简单的例子FreeMarker入门教程,说到底,就是替换模板 ...

jeecms标签问题

刚开始学jeecms,看官网上讲[@cms_channel_list]标签时,属性中并没有 tpl这个 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本