How do you make methods that work across multiple views? For example. I created this:
- (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;
}
I want to be able to call the setPageTitle method on UILabels within different views. How do I go about doing this? Where do I put this code to make it work? I only want to put it in 1 file and have it work in different views. Thank you.
I would suggest making this a category on the UIView class.
UIView+PageTitle.h
UIView+PageTitle.m