这是我的基本实现,手动。这可能是非常低的性能(大概:它强制视图重绘,而不是缓存输出?)
平铺视图.h
@interface TilingView : UIView
@property( nonatomic, retain ) UIView* templateView;
@end
平铺视图.m
@implementation TilingView
@synthesize templateView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
int cols = 1 + self.bounds.size.width / self.templateView.bounds.size.width;
int rows = 1 + self.bounds.size.height / self.templateView.bounds.size.height;
CGContextRef context = UIGraphicsGetCurrentContext();
for( int k=0; k<rows; k++ )
for( int i=0; i<cols; i++ )
{
CGContextSaveGState(context);
CGContextTranslateCTM(context, i * self.templateView.bounds.size.width, k * self.templateView.bounds.size.height);
[self.templateView drawRect:rect];
CGContextRestoreGState(context);
}
}
@end