我有一个 iPad 应用程序,我在其中设置 UIView 的 initWithFrame: 方法中的 UILabel 的阴影颜色。当我使用以下语法时:
m_label.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.5];
我得到这个编译器错误:
'[' 标记之前的预期标识符
但是,当我使用以下语法时:
[m_label setShadowColor:[UIColor colorWithWhite:1.0 alpha:0.5]];
它毫无怨言地编译。
对 UILabel 的其他属性使用属性语法可以正常工作(shadowOffset、autoresizingMask、backgroundColor、font、textColor 等)。
顺便说一句,当语句很简单时,我会收到相同的错误消息:
m_label.shadowColor;
而这,例如,没有给出错误:
m_label.shadowOffset;
FWIW,整个方法如下所示:
#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;
}
有任何想法吗?