1.自定义UICollectionViewCell
自定义这个Cell的时候千万注意,因为UITableViewCell的自定义非常合理规范
但是UICollectionCell没有这样相关的自定义方式,外部调用它的时候是通过注册方式:
[collect registerClass:[LBCollectionViewCell class] forCellWithReuseIdentifier:@"cellid"];
这就坑爹了,怎么保证它一定调用呢,其实,每次使用它的时候都会对他计算frame,所以需要这样自定义:
#import "LBCollectionViewCell.h"
@implementation LBCollectionViewCell
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
_label = [[UILabel alloc] init];
[_label setFrame:CGRectMake(0, 0, 40, 40)];
[_label setCenter:self.contentView.center];
[_label setBackgroundColor:[UIColor clearColor]];
[self.contentView addSubview:_label];
}
return self;
}
@end
2.NSString 和 NSNumber炫酷的写法
FRDLivelyButton一个很巧妙的写法
代码如下:
NSString *const kSYFRDLivelyButtonLineWidth = @"kSYFRDLivelyButtonLineWidth";
layer.lineWidth = [[self valueForOptionKey:kSYFRDLivelyButtonLineWidth] floatValue];
kSYFRDLivelyButtonLineWidth: @(2.0),
意想不到吧!
甚至类似地可以这样写:
NSString *const kSYFRDLivelyButtonColor = @"kSYFRDLivelyButtonColor";
layer.strokeColor = [[self valueForOptionKey:kSYFRDLivelyButtonColor] CGColor];
-(id) valueForOptionKey:(NSString *)key
{
if (self.options[key]) {
return self.options[key];
}
return [SYFRDLivelyButton defaultOptions][key];
}
3.添加pch路径:
应该如下:
$(SRCROOT)/工程名/PrefixHeader.pch