滚动视图在使用时崩溃" UIImageRenderingModeAlwaysTemplate"

时间:2016-09-05 16:03:02

标签: ios objective-c core-data uiscrollview xcode7

我的应用程序崩溃,同时使用3个视图,每个视图包含12个按钮,这些按钮使用相同的图像,但每次使用不同的颜色,所以我使用

    -(void) addViewsToscroll
    {

        NSMutableArray *imgArray = [[NSMutableArray alloc] init];
        [imgArray addObject:FirstView];
        [imgArray addObject:secondView];
        [imgArray addObject:ThirdView];



        CGSize pageSize = scrollView.frame.size; // scrollView is an IBOutlet for our UIScrollView
        NSUInteger page = 0;
        for(UIView *view in imgArray) {
            [scrollView addSubview:view];

            // This is the important line
            view.frame = CGRectMake(pageSize.width * page++ +3, 0, pageSize.width-6 , pageSize.height);
            // We're making use of the scrollView's frame size (pageSize) so we need to;
            // +10 to left offset of image pos (1/2 the gap)
            // -20 for UIImageView's width (to leave 10 gap at left and right)
        }

        scrollView.contentSize = CGSizeMake(pageSize.width * [imgArray count], pageSize.height);
    }


-(void) setButtonsColor{
   NSString *localPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
                    NSString *imageBouton1 = [localPath stringByAppendingPathComponent:[[NSString alloc]initWithFormat:@"%ld-shapeDisplayUrl.png",(long)button.tag]];
                    NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL fileURLWithPath: imageBouton1]];
                    if (imgData == nil)
                    {

                    }else
                    {
                        UIImage *tintedImage = [[[UIImage alloc] initWithData:imgData] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

                        [button setImage:tintedImage forState:UIControlStateNormal];
                        button.tintColor=color1;
                        button.backgroundColor = color2;
                    }

}

但是当imaged分配给按钮并且颜色改变时,如果我从视图滚动到视图应用程序崩溃。

  

感谢您的帮助

0 个答案:

没有答案