You can use this code for hyperlinked button as well as underlined text . You know there is no facilities for such option in none of iPhone SDK. So you can try this. It works for me.
in .h file
@interface UnderLineLabel : UIButton{
CGFloat stockWidth;
}
@property(nonatomic,assign)CGFloat stockWidth;
@end
in .m file
@implementation UnderLineLabel
@synthesize stockWidth;
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat components[4] = {0.654901961, 0.662745098, 0.674509804, 1};
CGContextSetStrokeColor(context, components);
// Draw them with a 1.0 stroke width.
CGContextSetLineWidth(context, self.stockWidth);
// Draw a single line from left to right
CGContextMoveToPoint(context, 0, rect.size.height);
CGContextAddLineToPoint(context, rect.size.width, rect.size.height);
CGContextStrokePath(context);
}
- (void)dealloc {
[super dealloc];
}
@end
Advertisement
Categories: iPhone, Objective-C
Cocoa Touch, iPhone, Objective-C, XCode