about Uilabel and UIButton sometimes you need to add underscores, there are generally two ways to pass the default nsmutableattributedstring Settings, the second is to draw an underscore in the drawrect, this article on the simple choice of the first, the second is interested in their own research.
Uilabel Set the underline:
UILabel *label = [[UILabel alloc] Initwithframe:cgrectmake (Ten, +, 310,)]; Label.backgroundcolor = [Uicolor redcolor]; [Label setlinebreakmode:nslinebreakbywordwrapping]; Label.numberoflines =3; [Label Setfont:[uifont systemfontofsize:14]; nsmutableattributedstring *content = [[nsmutableattributedstring alloc]initwithstring:[nsstring stringWithFormat:@] Bowen Address: Http://www.cnblogs.com/xiaofeixiang Blog Park-flyelephant QQ Group: 228407086 "]; Nsrange Contentrange = {0,[content length]}; [Content Addattribute:nsunderlinestyleattributename Value:[nsnumber Numberwithinteger:nsunderlinestylesingle] Range:contentrange]; Label.attributedtext = content; [Self.view Addsubview:label];
UIButton Set the underline:
UIButton *button=[[uibutton Alloc]initwithframe:cgrectmake (Ten, $, ())]; nsmutableattributedstring *title = [[Nsmutableattributedstring alloc] initwithstring:@ "flyelephant"]; Nsrange Titlerange = {0,[title length]}; [title Addattribute:nsunderlinestyleattributename Value:[nsnumber Numberwithinteger:nsunderlinestylesingle] Range: Titlerange]; [Button Setattributedtitle:title forstate:uicontrolstatenormal]; [Button Setbackgroundcolor:[uicolor Redcolor]; [Button.titlelabel Setfont:[uifont systemfontofsize:14]; [Self.view Addsubview:button];
The final effect is as follows:
iOS development-uilabel and UIButton add underline