按鈕下自帶劃線 && 計算Label.text長度

按鈕下自帶劃線

UIButton *button = 

[UIButton buttonWithType:UIButtonTypeCustom];

button.frame = frame;


NSMutableAttributedString *content = [[NSMutableAttributedStrin alloc]initWithString:text];

NSRange contentRange = {0,[content length]};

[content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];

button.titleLabel.attributedText=content;


計算寬度


UIFont * font = [UIFont systemFontOfSize:13];

    CGSize lastSize = [str sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,nil]];

CGFloat w = lastSize.width;


發佈了17 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章