Uiunderlinedbutton.h Code
- @interface Uiunderlinedbutton:uibutton {
- }
- + (Uiunderlinedbutton *) Underlinedbutton;
- @end
UIUNDERLINEDBUTTON.M Code
- @implementation Uiunderlinedbutton
- + (uiunderlinedbutton*) Underlinedbutton {
- uiunderlinedbutton* button = [[Uiunderlinedbutton alloc] init];
- return [button autorelease];
- }
- -(void) DrawRect: (cgrect) rect {
- CGRect textrect = self.titleLabel.frame;
- Need to put the line at top of descenders (negative value)
- CGFloat descender = Self.titleLabel.font.descender;
- Cgcontextref contextref = Uigraphicsgetcurrentcontext ();
- Set to same colour as text
- Cgcontextsetstrokecolorwithcolor (Contextref, Self.titleLabel.textColor.CGColor);
- Cgcontextmovetopoint (Contextref, textrect.origin.x, TEXTRECT.ORIGIN.Y + textRect.size.height + descender);
- Cgcontextaddlinetopoint (contextref, textrect.origin.x + textRect.size.width, TEXTRECT.ORIGIN.Y + TextRect.size.height + descender);
- Cgcontextclosepath (CONTEXTREF);
- Cgcontextdrawpath (Contextref, Kcgpathstroke);
- }
- @end
iOS development: Customizing UIButton with underlined text