iphone - UIButton 的按钮文本如何加下划线?

标签 iphone objective-c cocoa-touch ios4

文本来自数据库。我想将它用于按钮并在按钮的文本下划线。我该怎么做?

最佳答案

在 iOS 6 中,NSAttributedString 用于修改文本,您可以将“NSMutableAttributedString”用于使用单个 UIButton 或 UILabel 的多色文本、字体、样式等。

NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:@"The Underlined text"];

// making text property to underline text-
[titleString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [titleString length])];

// using text on button
[button setAttributedTitle: titleString forState:UIControlStateNormal];

关于iphone - UIButton 的按钮文本如何加下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5442405/

相关文章:

iphone - iPhone 应用程序的无线部署

iphone - 创建自定义 NSRunLoop

ios - 在 UITextView 中单击 url 时选择浏览器

iphone - 从 UIImage 生成哈希值

iphone - 确定摇动速度

iphone - 如何将时间值的NSString表示形式转换为包含小时和分钟的两个NSInteger形式?

iphone - 我可以为 Cocoa Touch 应用程序开发自己的 objective-C 框架吗?

ios - 使用导航 Controller 时如何跳过 2 个 View

ios - 在 "NSDictionary *"类型的对象上找不到写入字典元素的预期方法

ios - 如何在两个 UIView 之间实现 "90% slide"