Method One:
[OBJC]View Plaincopyprint?
- nsmutableattributedstring *str = [[nsmutableattributedstring alloc] initwithstring:@ "View all winning records"];
- Nsrange Strrange = {0,[str length]};
- [Str addattribute:nsunderlinestyleattributename value:[nsnumber Numberwithinteger: Nsunderlinestylesingle] Range:strrange];
- [_awarddisplaybtn setattributedtitle:str Forstate:uicontrolstatenormal];
Method Two:
HyperlinksButton.h
[OBJC]View Plaincopyprint?
- #import <UIKit/UIKit.h>
- @interface Hyperlinksbutton:uibutton
- {
- Uicolor *linecolor;
- }
- -(void) SetColor: (uicolor*) color;
- @end
Hyperlinksbutton.m
[OBJC]View Plaincopyprint?
- #import "HyperlinksButton.h"
- @implementation Hyperlinksbutton
- -(ID) initWithFrame: (CGRect) Frame
- {
- Self = [super Initwithframe:frame];
- if (self) {
- }
- return self ;
- }
- -(void) SetColor: (uicolor *) color{
- LineColor = [color copy];
- [self setneedsdisplay];
- }
- -(void) DrawRect: (cgrect) rect {
- CGRect textrect = self. Titlelabel. Frame;
- Cgcontextref contextref = Uigraphicsgetcurrentcontext ();
- CGFloat descender = self. Titlelabel. Font. descender;
- if ([LineColor Iskindofclass:[uicolor class]]) {
- Cgcontextsetstrokecolorwithcolor (Contextref, LineColor. Cgcolor);
- }
- Cgcontextmovetopoint (Contextref, Textrect. Origin. x, Textrect. Origin. Y + textrect. Size. Height + descender+1);
- Cgcontextaddlinetopoint (Contextref, Textrect. Origin. x + textrect. Size. width, textrect. Origin . Y + textrect. Size. Height + descender+1);
- Cgcontextclosepath (CONTEXTREF);
- Cgcontextdrawpath (Contextref, Kcgpathstroke);
- }
- @end
Copy this class directly into the project, and then change the required underlined Button class name to Hyperlinksbutton, provide setcolor: This interface, you can set the underline color, the code is very simple, not explained. UILabel have the same benefit.
Example results:
Label Plus Glide Line