【发布时间】:2012-03-02 08:42:08
【问题描述】:
您如何制作可跨多个视图工作的方法?例如。我创建了这个:
- (void)setPageTitle:(UILabel *)title withText:(NSString *)text
{
UIColor *pageTextColor = [UIColor colorWithRed:18.0/255.0 green:79.0/255.0 blue:118.0/255.0 alpha:1.0];
// Set page title
UIFont *font = [UIFont fontWithName:@"PassionOne-Regular" size:23];
[title setFont:font];
[title setText: text];
title.textColor = pageTextColor;
title.shadowColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0];
title.shadowOffset = CGSizeMake(0, 1);
CGRect titleRect = [title textRectForBounds:title.bounds limitedToNumberOfLines:999];
CGRect tr = title.frame;
tr.size.height = titleRect.size.height;
title.frame = tr;
}
我希望能够在不同视图中调用 UILabel 上的 setPageTitle 方法。我该怎么做呢?我在哪里放置此代码以使其工作?我只想把它放在 1 个文件中,让它在不同的视图中工作。谢谢。
【问题讨论】:
-
所有您的视图都是同一个自定义类型吗?
-
如果他们都有共同的自定义类型,一个简单的实例方法就可以了,不是吗?