Ros*_*oss 2 iphone methods ios ios5
如何制作跨多个视图的方法?例如.我创造了这个:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在不同视图中的UILabels上调用setPageTitle方法.我该怎么做呢?我在哪里放置此代码才能使其正常工作?我只想把它放在1个文件中,让它在不同的视图中工作.谢谢.
我建议将它作为UIView类的一个类别.
UIView的+ PageTitle.h
@interface UIView (PageTitle)
- (void)setPageTitle:(UILabel *)title withText:(NSString *)text;
@end
Run Code Online (Sandbox Code Playgroud)
UIView的+ PageTitle.m
#import "UIView+PageTitle.h"
@implementation UIView (PageTitle)
- (void)setPageTitle:(UILabel *)title withText:(NSString *)text {
// your implementation
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1677 次 |
| 最近记录: |