Hi guys,
I'm a beginner of iPhone Programming. I want to subclass UIButton so that I can have two labels -- one on left side for displaying title and one on right side for displaying value.
To use this new button class, I add a button in Interface Builder, then modify the the class name from UIButton to ValueButton.
My problem is, the button displays neither border nor my additional label. Here's my codes:
ValueButton.h
ValueButton.m
Do I miss something? Please help me.
I'm a beginner of iPhone Programming. I want to subclass UIButton so that I can have two labels -- one on left side for displaying title and one on right side for displaying value.
To use this new button class, I add a button in Interface Builder, then modify the the class name from UIButton to ValueButton.
My problem is, the button displays neither border nor my additional label. Here's my codes:
ValueButton.h
Code:
#import <UIKit/UIKit.h>
@interface ValueButton : UIButton {
UILabel * valueLabel;
}
@property (nonatomic, retain) NSString * value;
@end
ValueButton.m
Code:
#import "ValueButton.h"
@implementation ValueButton
#pragma mark -
- (NSString *) value
{
return valueLabel.text;
}
- (void) setValue:(NSString *)v
{
valueLabel.text = v;
}
#pragma mark -
- (id) init
{
self = [super init];
if (self != nil) {
valueLabel = [[UILabel alloc] init];
}
return self;
}
- (void) layoutSubviews
{
[super layoutSubviews];
valueLabel.frame = self.titleLabel.frame;
self.titleLabel.textAlignment = UITextAlignmentLeft;
valueLabel.textAlignment = UITextAlignmentRight;
[self addSubview:valueLabel];
}
- (void)dealloc {
[valueLabel release];
[super dealloc];
}
Do I miss something? Please help me.