gpt4 book ai didi

ios - 如何以编程方式对齐和移动两个标签?

转载 作者:行者123 更新时间:2023-11-29 02:52:14 24 4
gpt4 key购买 nike

我必须使用两个顺序标签,例如:

Title: New Title

但是 title 是一个本地化的字符串,在不同的语言中会改变他的长度。如何以编程方式在 Title 末尾移动 New title 的 UILabel?使用 autoLayout,在 StackOverflow 上找到的旧解决方案似乎不起作用。

最佳答案

使用一个字符串

  NSString *str = [NSString stringWithFormat:@"Title:%@   Newtitle:%@", Title, newtitle];

如果标题和文本的颜色不同,请使用此示例中的属性字符串 -

   NSMutableAttributedString *str = [[NSMutableAttributedString alloc]  initWithString:@"Its an test attributed string."];
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(3,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(10,7)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)];

关于ios - 如何以编程方式对齐和移动两个标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24360781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com