gpt4 book ai didi

ios - 如何以编程方式在 iOS Objective C 中使文本标签的某些部分加粗?

转载 作者:行者123 更新时间:2023-11-28 18:49:04 25 4
gpt4 key购买 nike

enter image description here

我试过这样

#define KPrivacyText @"Your privacy is very important to us. We are committed \nto earn  your trust by safeguarding your personal \ninformation. All the information you provide to us is \nsecurely maintained and is kept strictly confidential. We \ndo not, and will not provide any personal information to \nyour organisation without your consent.\n\nThe governing principles: \n\n\n\u2022\tInformation is kept strictly confidential and secure. \n\n\n\u2022\tInformation is only used for the purposes stated.\n\n\n\u2022\tInformation is only shared with your consent."

_privacyText.text = KPrivacyText;

我希望“管理原则:”以粗体显示。是否有类似 \n 但用于粗体的东西?

最佳答案

你必须使用 NSAttributedText 来实现它。

NSString *boldFontName = [[UIFont boldSystemFontOfSize:12] fontName];
NSString *yourString = ...;
NSRange boldedRange = NSMakeRange(22, 4);

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:yourString];

[attrString beginEditing];
[attrString addAttribute:kCTFontAttributeName
value:boldFontName
range:boldedRange];

[attrString endEditing];
//draw attrString here...

关于ios - 如何以编程方式在 iOS Objective C 中使文本标签的某些部分加粗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45454187/

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