@interface MyButton : UIButton
- (void)drawRect:(CGRect)rect
{
// Drawing code
[super drawRect:rect];
// add code to draw lines here
}
UIButton* button = [[MyButton alloc] initWithFrame:frame];
@interface Button : UIButton
{
}
@implementation Button
- (void)drawRect:(CGRect)rect
{
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 1.0);
// Draw a single line from left to right
CGContextMoveToPoint(context,10, 22.0);
CGContextAddLineToPoint(context, 100, 22.0);
CGContextStrokePath(context);
// Drawing code
}
The screenshot's a little small but I can see that the title is underlined. Great.
So is the baseline = ascent+descent relative to the bounds.y of the button?
One other thing: you might want the color of the underline to have some alpha value other than 1. That way the underline mixes more nicely with the text rather than simply overwriting it, especially if the underline RGB is different from the text foreground color.
I think someone should write a class that handles just that.
It seems like doing it with a button has too much overhead for a simple link.
Ideas:
Class called Link
have the class take a display name and a URL string
have the class load the page when the link is pressed
I have created a subclass using UIButton with code as given below
Though this code draws a line at the specified positionCode:@interface Button : UIButton { } @implementation Button - (void)drawRect:(CGRect)rect { CGContextRef context=UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); // Draw them with a 2.0 stroke width so they are a bit more visible. CGContextSetLineWidth(context, 1.0); // Draw a single line from left to right CGContextMoveToPoint(context,10, 22.0); CGContextAddLineToPoint(context, 100, 22.0); CGContextStrokePath(context); // Drawing code }
but i need to draw it exactly below the title. Also the line's length should be consistent with the title length
Any idea??
I am in dire need of underlined text in UIButton.
Thanks
CGSize dynamicSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(99999, 99999) lineBreakMode:self.lineBreakMode];
CGContextMoveToPoint(context, 0, dynamicSize.height);
CGContextAddLineToPoint(context, dynamicSize.width, dynamicSize.height);
arnieterm, have you read through the iPhone Human Interface Guidelines document (MobileHIG.pdf)? Cuz what you appear to be proposing for your UI doesn't seem to jive with what Apple recommends.