简体   繁体   中英

How to overlay two images in ios6 with transparency

I am trying to overlay two images and put text on top in a view that I have. I have this working perfectly in ios7. Here is a screen shot of the results

所需结果

Right now the gradient is simply an image on top of the other image as seen here in my layout

布局

This works great except for when I test on my phone with ios6. Then everything goes nuts as seen here. *I've actually deleted the gradient layer and ran the app again and the background image remains the same size (about half of what it should be).

图片在iOS6中混乱

As you can see, the background image is only half of what it should be, and the second image is not overlaying. I've been at this for 5 hours and can't seem to find a solution that works.

Here is the code that sets the background image

-(void) SetDetails
{
if(_curInfo)
{


    _lblTopName.text = _curInfo.company_name;
    if(!_curInfo.img)
    {
        showActivity(self);
        dispatch_queue_t aQueue1 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_async(aQueue1, ^{
            _curInfo.img = getImageFromURL([NSString stringWithFormat:@"%@%@", g_serverUrl, _curInfo.imgPath]);
            dispatch_async(dispatch_get_main_queue(), ^{
                hideActivity();
                [_imgCompany setImage:_curInfo.img];
            });
        });
    }
    [_imgCompany setImage:_curInfo.img];



    /* FIX IMAGE SIZE */
    _imgCompany.contentMode=UIViewContentModeScaleAspectFill;
    CGRect photoFrame = _imgCompany.frame;
    photoFrame.size = CGSizeMake(320, 180);
    _imgCompany.frame=photoFrame;
    [_imgCompany setClipsToBounds:YES];


        _lblDistance.text = [NSString stringWithFormat:@"%.2f miles", _curInfo.distance];


    _lblReward.text=_curInfo.reward;

    CGFloat scrollViewHeight = 0.0f;
    for (UIView* view in scroller.subviews)
    {
        scrollViewHeight += view.frame.size.height;

    }

    [scroller setContentSize:(CGSizeMake(320, scrollViewHeight))];

}
}

Any help is greatly appreciated. I'm not opposed to drawing the gradient onto the image either.

Additional Info:

Here is how I have the two image views setup.

渐变图像视图

背景图像视图

You need to unstick the 'opaque' option on your image view, given that it isn't opaque.

As to the other spacing issue, I'd guess it's a mismatch between iOS 7 view controllers always acting as if they had wantsFullScreenLayout set to YES but the default having been NO under iOS 6. The rest of your image is probably underneath your navigation bar. It looks like you're part trying the interface builder and part doing programmatic layout — why did you add the code underneath FIX IMAGE SIZE and what happens if you remove it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM