我有此代碼,其中應重複相同的UIImage:一個UIImage CoreGraphics在創建不重複
UIView *paperMiddle = [[UIView alloc] initWithFrame:CGRectMake(0, 34, 320, rect.size.height - 34)];
UIImage *paperPattern = paperBackgroundPattern(context);
paperMiddle.backgroundColor = [UIColor colorWithPatternImage:paperPattern];
[self addSubview:paperMiddle];
而這正是paperBackgroundPattern
方法:
UIImage *paperBackgroundPattern(CGContextRef context) {
CGRect paper3 = CGRectMake(10, -15, 300, 16);
CGRect paper2 = CGRectMake(13, -15, 294, 16);
CGRect paper1 = CGRectMake(16, -15, 288, 16);
//Shadow
CGContextSetShadowWithColor(context, CGSizeMake(0,0), 10, [[UIColor colorWithWhite:0 alpha:0.5]CGColor]);
CGPathRef path = createRoundedRectForRect(paper3, 0);
CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextAddPath(context, path);
CGContextFillPath(context);
//Layers of paper
CGContextSaveGState(context);
drawPaper(context, paper3);
drawPaper(context, paper2);
drawPaper(context, paper1);
CGContextRestoreGState(context);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 1), NO, 0);
UIImage *paperImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return paperImage;
}
它不重複圖片。這裏有圖像的結果是它顯示爲屏幕的頂部像素(這不是我給出的框架)。
任何想法爲什麼?
請不要刪除並重新發布您的問題http://stackoverflow.com/questions/9767477/isnt-repeating-background-created-in-coregraphics。相反,編輯並改進它們。 – 2012-03-19 21:08:15