Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIColor `-colorWithPatternImage:` alpha blending problem solution. (iOS SDK 4.1)

Solution note, not a question.

I used this code to set background as a pattern image:

UIImage *bg     =   SomeImage();
UIColor *bgc    =   [UIColor colorWithPatternImage:bg];
[self setBackgroundColor:bgc];
[self setOpaque:NO];

This works, but alpha blending doesn't work. Might be a bug. How to make it work?

  • Platform: iOS SDK 4.1
like image 406
eonil Avatar asked Oct 10 '10 07:10

eonil


1 Answers

This code make it alpha blended on both of simulator and device.

UIImage *bg     =   SomeImage();
UIColor *bgc    =   [UIColor colorWithPatternImage:bg];
[self setBackgroundColor:bgc];
[self setOpaque:NO];
[[self layer] setOpaque:NO];      // Added this line.
like image 126
eonil Avatar answered Sep 20 '22 20:09

eonil