UIViewContentMode涵盖了您经常需要的几个职位(中心、ScaleToFill、ScaleToFit),以及我怀疑大多数人很少使用的负载(TopRight,有人吗?)
但它似乎缺少了一个明显的例子:“重复”。
有办法有效地重复UIView的内容吗?也就是说,平铺视图,当你调整尺寸时,它只是发现/覆盖了更多的平铺内容?
(显然,我说的不是UIImageViews - UIImage/UIColor有一种处理位图数据的方法,但这是另外一个问题。我说的是UIView,意思是“drawRect”
发布于 2012-09-11 00:44:30
这是我的基本实现,手工操作。这可能是可怕的低性能(想必:它迫使视图重绘,而不是缓存输出?)
TilingView.h
@interface TilingView : UIView
@property( nonatomic, retain ) UIView* templateView;
@endTilingView.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);
}
}
@endhttps://stackoverflow.com/questions/12359972
复制相似问题