PDA

View Full Version : How to avoid black color for image as background




mikezang
Jan 8, 2011, 10:31 AM
I have a image, I am using code as below to set it as UIView's background color, but I found there are black color, how can I avoid black with Transparency?



robbieduncan
Jan 8, 2011, 10:32 AM
What code? You haven't posted any

mikezang
Jan 8, 2011, 10:52 AM
What code? You haven't posted any
Sorry, I forgot to paste.


self.titleView = [[UIView alloc] initWithFrame:CGRectMake(30, 10, 256, 50)];
self.titleView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"title.png"]];
[self.titleView addSubview:title];
[title release];

robbieduncan
Jan 8, 2011, 11:01 AM
As you have not set the opaque (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html%23//apple_ref/occ/instp/UIView/opaque) property of the view to NO the drawing system assumes (as it should) that the view has no areas with alpha < 1.0. I'd try setting that property.

mikezang
Jan 8, 2011, 11:23 AM
As you have not set the opaque (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html%23//apple_ref/occ/instp/UIView/opaque) property of the view to NO the drawing system assumes (as it should) that the view has no areas with alpha < 1.0. I'd try setting that property.
Great! I got it, thank you very much!

zerocustom1989
Jan 8, 2011, 04:51 PM
Great! I got it, thank you very much!

optionally, since this doesnt seem to be a patterned image.(forgive me if it is)

You can use a UIImageView. Set the image property to your titleimage.png and set the backgroundcolor of the UIImageView to clearColor.