ios - 给 UILabel 的某个部分加下划线

标签 ios uilabel

如标题所示,我需要在 UILabel 的某个部分加下划线。例如: 请单击 ESPNSoccernet 阅读最新的足球新闻。 我想在 ESPNSoccernet 一词下划线。这是因为我希望它可以点击并且需要链接到网站。

在执行此操作时需要一些指导。如果还有其他方法,请告诉我...

最佳答案

对于 ios 6,你可以使用 AttributedStrings

NSMutableAttributedString *yourString = [[NSMutableAttributedString alloc] initWithString:@"Please click ESPNSoccernet to read the latest Football News."];
[yourString addAttribute:NSUnderlineStyleAttributeName
                        value:[NSNumber numberWithInt:1]
                        range:(NSRange){0,25}];

label.attributedText = [yourString copy];

您还可以使用第 3 方 UILable 库 TTTAttributedLabel .

关于ios - 给 UILabel 的某个部分加下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16519774/

相关文章:

ios - 为 UIImage 创建 alpha

swift - 尽管有多种方法,标签仍未在容器内调整大小

ios - MultiLine UIlabel 不显示所有文本?

swift - 用UILabel字母实现旋转、移动、缩放动画效果。 swift

ios - 使用 UiButton 反复更改 UILabel 文本

ios - UILabel具有自动布局的丑陋旋转动画

iphone - iPad 应用强制旋转

ios - 为什么可能需要为iOS或macOSbuild设置 “supported document types”?

ios - 地理围栏 iOS8 : Require Background Mode for iOS Geofencing

ios - 动态更改服务器上的 .ipa 文件