1. 程式人生 > >btn下劃線 字型左對齊

btn下劃線 字型左對齊

    NSString *appleNum = [NSString stringWithFormat:@"%@",ObjectToNumber(model.amount)];

    // 下劃線

    NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};

    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%.2f",[appleNum floatValue]] attributes:attribtDic];

//字型和下劃線顏色

      [attribtStr addAttribute:NSForegroundColorAttributeName value:ContentColor range:NSMakeRange(0,attribtStr.length)];

    //賦值

    [appleBtn setAttributedTitle:attribtStr forState:(UIControlStateNormal)];

//字型左對齊 nstextAlignment 那個方法不行

appleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

 

上面同樣適用於 Lable