在UIView中重叠重复图像

时间:2017-05-11 13:35:44

标签: ios objective-c

我有图像(a),我希望它像(b)中的偏移一样重叠。但我最终得到了(c)

enter image description here

这段代码给了我(c)

UIImage * imgLeftBorder = [UIImage imageNamed:@"border_left"];

 UIView * leftBorder = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, screenHeight - 25)];
    [leftBorder setBackgroundColor:[UIColor colorWithPatternImage:imgLeftBorder]];
    [self.view addSubview:leftBorder];

我玩弄了偏移和插图,但我无法达到我的结果。有人做过这样的事吗?

1 个答案:

答案 0 :(得分:0)

用一段时间怎么样?

int currY = 0;

while(currY < screenHeight) {
    UIImageView *leftBorder = [[UIImageView alloc] initWithFrame:CGRectMake(0, currY, imgLeftBorder.size.width, imgLeftBorder.size.width)];
    leftBorder.image = imgLeftBorder;
    [self.view addSubview:leftBorder];
    currY += imgLeftBorder.size.width - 25;
}