How to preserve image transparency when using colorWithPatternImage:

前端 未结 3 1263
遇见更好的自我
遇见更好的自我 2020-12-30 03:04

I have an image prepared with transparency, like this:

\"alt

With two UIviews, I configure the b

相关标签:
3条回答
  • 2020-12-30 03:33

    all you have to do is set opaque to NO after setting the colorWithPatternImage.

    self.dashedView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"red_square.png"]];
    self.dashedView.opaque = NO;
    
    0 讨论(0)
  • 2020-12-30 03:44

    Pattern images should be keeping the transparency just fine.

    Try [self.dashedView setOpaque:NO]

    0 讨论(0)
  • 2020-12-30 03:58

    Yar, thanks for the feedback.

    I found this only happens on iOS 4.3.x but not on iOS 5.0.x. So on 4.3.x I had to do what Yar id and set opaque to NO, then set background image, then set to YES.

    UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.opaque = YES; // fix for strange issue in 4.x, need to set YES, set bg color image, then set back to NO
    cancelButton.backgroundColor = [UIColor colorWithPatternImage: cancelImage];
    cancelButton.opaque = NO;
    
    0 讨论(0)
提交回复
热议问题