【发布时间】:2011-03-19 06:26:29
【问题描述】:
所以我的代码中有这样的内容:
leftMostLabel = [[UILabel alloc] initWithFrame:CGRectMake(60.0f, 2.0f, 80.0f, 40.0f)];
leftMostLabel.text = @"Some text";
leftMostLabel.textColor = [UIColor colorWithWhite:1.0 alpha:1.0];
leftMostLabel.backgroundColor = [UIColor clearColor];
leftMostLabel.textAlignment = UITextAlignmentCenter;
leftMostLabel.font = [UIFont boldSystemFontOfSize:13.0];
leftMostLabel.userInteractionEnabled = NO;
centerLeftLabel = [[UILabel alloc] initWithFrame:CGRectMake(115.0f, 2.0f, 80.0f, 40.0f)];
centerLeftLabel.text = currentDate;
centerLeftLabel.textColor = [UIColor colorWithWhite:1.0 alpha:1.0];
centerLeftLabel.backgroundColor = [UIColor clearColor];
centerLeftLabel.textAlignment = UITextAlignmentCenter;
centerLeftLabel.font = [UIFont systemFontOfSize:12.0];
centerLeftLabel.userInteractionEnabled = NO;
这很好用,但我重复了很多次这种格式。理想情况下,我希望将变量(leftMostLabel、centerLeftLabel 等)传递给一个函数,该函数根据我传递给它的 变量名称 在幕后为我创建标签,如以及我提供的任何其他参数。这可能吗?如果是这样,我将如何处理?
提前致谢!
【问题讨论】:
标签: objective-c cocoa-touch coding-style