使文本在 xcode 中加下划线 [英] Make text underlined in xcode

查看:55
本文介绍了使文本在 xcode 中加下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在制作一个应用程序,它要求文本视图文本的某个部分带有下划线.有没有一种简单的方法可以做到这一点,例如将其设为粗体和斜体,或者我必须制作并导入自定义字体?提前感谢您的帮助!

Hey I'm making an app that requires a certain part of a text view's text to be underlined. is there a simple way to do this like for making it bold and italics or must i make and import a custom font? thanks for the help in advance!

推荐答案

这就是我所做的.它的作用就像黄油一样.

This is what i did. It works like butter.

1) 将 CoreText.framework 添加到您的框架中.

1) Add CoreText.framework to your Frameworks.

2) 在需要下划线标签的类中导入.

2) import <CoreText/CoreText.h> in the class where you need underlined label.

3) 编写以下代码.

NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"My Messages"];
[attString addAttribute:(NSString*)kCTUnderlineStyleAttributeName
                  value:[NSNumber numberWithInt:kCTUnderlineStyleSingle]
                  range:(NSRange){0,[attString length]}];
self.myMsgLBL.attributedText = attString;
self.myMsgLBL.textColor = [UIColor whiteColor];

这篇关于使文本在 xcode 中加下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆