Hello all, I have a UILabel subclass "UIToggleLabel", designed to toggle its value when the user taps on it, between two different values. For some reason, in 2.0, it appears in grey (I suspect it's only rendering a shadow for it), whilst in 2.1 and upwards, it renders fine.
Here's my class:
I've tracked down the problem to the bold lines; removing them (and passing through "t" straight to self.text), makes the text black again (but obviously without any toggling functionality).
I'd really like to continue compiling this for 2.0. Does anyone have any idea why this might be happening?
Here's my class:
Code:
#import <UIKit/UIKit.h>
@interface UIToggleLabel : UILabel {
NSString * mainText;
NSString * alternateText;
BOOL showFront;
}
- (void)toggle;
@property (nonatomic, copy) NSString * mainText;
@property (nonatomic, copy) NSString * alternateText;
@end
@implementation UIToggleLabel
@synthesize mainText;
@synthesize alternateText;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
showFront = YES;
mainText = nil;
alternateText = nil;
self.userInteractionEnabled = YES;
}
return self;
}
- (void)setMainText:(NSString *)t {
if (mainText != nil) [mainText release];
[B] mainText = [t copy];[/B]
if (showFront == YES) {
self.text = t;
}
}
- (void)setAlternateText:(NSString *)t {
if (alternateText != nil) [alternateText release];
[B] alternateText = [t copy];[/B]
if (showFront == NO) {
self.text = alternateText;
}
}
- (void)toggle {
showFront = !showFront;
if (showFront) {
self.text = self.mainText;
} else {
self.text = self.alternateText;
}
[self setNeedsDisplay];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self toggle];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)dealloc {
[mainText release];
[alternateText release];
[super dealloc];
}
@end
I've tracked down the problem to the bold lines; removing them (and passing through "t" straight to self.text), makes the text black again (but obviously without any toggling functionality).
I'd really like to continue compiling this for 2.0. Does anyone have any idea why this might be happening?