【问题标题】:UIButton dashed underline in Objective c目标c中的UIButton虚线下划线
【发布时间】:2015-02-19 09:22:49
【问题描述】:

普通下划线有效,但虚线下划线似乎无效?

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
btn.frame = CGRectMake(100, 10, 300, 300);
NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:@"Durga Vundavalli"];

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

// using text on button
[btn setAttributedTitle: titleString forState:UIControlStateNormal];
[self.view addSubview:btn];

以下是文档中的枚举:

typedef NS_ENUM(NSInteger, NSUnderlineStyle) {
    NSUnderlineStyleNone                                = 0x00,
    NSUnderlineStyleSingle                              = 0x01,
    NSUnderlineStyleThick NS_ENUM_AVAILABLE_IOS(7_0)    = 0x02,
    NSUnderlineStyleDouble NS_ENUM_AVAILABLE_IOS(7_0)   = 0x09,

    NSUnderlinePatternSolid NS_ENUM_AVAILABLE_IOS(7_0)      = 0x0000,
    NSUnderlinePatternDot NS_ENUM_AVAILABLE_IOS(7_0)        = 0x0100,
    NSUnderlinePatternDash NS_ENUM_AVAILABLE_IOS(7_0)       = 0x0200,
    NSUnderlinePatternDashDot NS_ENUM_AVAILABLE_IOS(7_0)    = 0x0300,
    NSUnderlinePatternDashDotDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0400,

    NSUnderlineByWord NS_ENUM_AVAILABLE_IOS(7_0) = 0x8000
}

【问题讨论】:

    标签: ios objective-c iphone uibutton


    【解决方案1】:

    您不能只输入NSUnderlinePatternDot。如果你想要两行点怎么办?您必须使用PatternStyle

    [titleString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:(NSUnderlinePatternDot|NSUnderlineStyleSingle)] range:NSMakeRange(0, [titleString length])];
    

    如文档所述,您必须使用掩码:

    讨论
    样式、模式和可选的字掩码是 OR'd 一起产生NSUnderlineStyleAttributeName 的值和 NSStrikethroughStyleAttributeName.

    【讨论】:

      猜你喜欢
      • 2012-04-26
      • 2011-02-07
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多