I have an iPad app in which I'm setting the shadow color of a UILabel in a UIView's initWithFrame: method. When I use the following syntax:
m_label.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.5];
I get this compiler error:
Expected identifier before '[' token
However, when I use the following syntax:
[m_label setShadowColor:[UIColor colorWithWhite:1.0 alpha:0.5]];
It compiles without complaint.
Using property syntax for other properties of the UILabel is working fine (shadowOffset, autoresizingMask, backgroundColor, font, textColor, etc.).
Incidentally, I get the same error message when the statement is simply this:
m_label.shadowColor;
Whereas this, for example, gives no error:
m_label.shadowOffset;
FWIW, the entire method looks like this:
#define shadowColor [UIColor colorWithWhite:1.00 alpha:0.5]
#define selectedColor [UIColor colorWithWhite:0.25 alpha:1.0]
#define unselectedColor [UIColor colorWithWhite:0.45 alpha:1.0]
#define CLOSEBUTTON_WIDTH 26.0
#define CLOSEBUTTON_HEIGHT 26.0
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
m_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height)];
m_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
m_imageView.backgroundColor = [UIColor clearColor];
m_imageView.image = [[UIImage imageNamed:@"tab.png"] stretchableImageWithLeftCapWidth:8.0 topCapHeight:0.0];
m_imageView.highlightedImage = [[UIImage imageNamed:@"tabSelected.png"] stretchableImageWithLeftCapWidth:8.0 topCapHeight:0.0];
m_label = [[UILabel alloc] initWithFrame:CGRectZero];
m_label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
m_label.backgroundColor = [UIColor clearColor];
m_label.font = [UIFont boldSystemFontOfSize:12.0];
m_label.textColor = unselectedColor;
m_label.shadowOffset = CGSizeMake(0.0, 1.0);
m_label.shadowColor = shadowColor; // Expected identifier before '[' token
[m_label setShadowColor:shadowColor];
m_closeButton = [[UIButton alloc] initWithFrame:CGRectMake(9.0, 1.0, CLOSEBUTTON_WIDTH, CLOSEBUTTON_HEIGHT)];
[m_closeButton setBackgroundImage:[UIImage imageNamed:@"tabClose.png"] forState:UIControlStateNormal];
[m_closeButton addTarget:self action:@selector(closeTab) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:m_imageView];
[self addSubview:m_label];
[self addSubview:m_closeButton];
self.backgroundColor = [UIColor clearColor];
}
return self;
}
Any ideas?