首页 \ 问答 \ 以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)

以编程方式标签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;

相关问答

更多
  • 这是一个非常全面的指导,我认为是必读: 异常和错误处理 - C ++常见问题或C ++常见问题 作为一般的经验法则,当您的程序可以识别出阻止执行的外部问题时,抛出异常。 如果您从服务器接收数据,并且数据无效,则抛出异常。 磁盘空间不足? 抛出异常 宇宙射线阻止您查询数据库? 抛出异常 但是如果您从自己的程序中获取一些无效数据 - 不要抛出异常。 如果你的问题来自你自己的坏代码,最好使用ASSERT来防范它。 需要异常处理来识别程序无法处理的问题,并告诉他们有关用户的问题,因为用户可以处理它们。 但程序中的错 ...
  • 我建议,不要在此方法中捕获异常,而是让它引发异常并从您调用的任何地方捕获它。 换句话说,不要把你的try catch放在那个方法中。 将try catch放在调用该方法的任何地方,并捕获它可以提升的内容。 所以,请改为: import traceback def ReadFile(): with open("/etc/passwd") as file: data = file.read() return data try: r = ReadFile() excep ...
  • 有几种方法可以解决这个问题。 第一种是更改返回函数的返回类型,而不是通过值返回类,通过std::unique_ptr传递它。 std::unique_ptr可以为null,因此如果有异常,则可以返回null unique_ptr否则只需将unique_ptr返回给您创建的对象。 另一种选择是使用boost::optional或std::optional 。 您现在可以使用boost::optional但std::optional是C ++ 17的功能,因此它的可用性有限。 就个人而言,我更喜欢可选方法,因为 ...
  • 来自GetEval的selenium文档 : 获取评估指定JavaScript代码段的结果。 代码段可能有多行,但只会返回最后一行的结果。 因此,您只需要return : string code = selenium.GetEval( "var win = this.browserbot.getUserWindow(); "+ "win.editAreaLoader.GetValue(win.loadedCodeEditorID);" ); From the selenium document ...
  • 将我的评论转换为答案: 你应该使用像: def retry(function): @wraps(function) def _retry(*args, **kwargs): try: reply = function(*args, **kwargs) print "reply: ", reply return reply except PDError as msg: ...
  • 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 plpg ...
  • 使用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') --output: ...
  • 让您的函数返回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(), _TRUNCA ...
  • 这是你应该处理的......我在你的代码中添加了'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_principa ...
  • 这似乎有效: function functionWhichCreatesOutputThenCausesAnException() { "hello" 1/0 "world" } try { $result = @() functionWhichCreatesOutputThenCausesAnException | foreach {$result += $_} } catch { $($error[0]) } This seems to work: ...

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)