Setting background color UIVIew

EDIT: People keep visiting this post, which doesnโ€™t have a lot of good information, so Iโ€™ll put it here to help you guys: Try setting a property of backgroundColoryours UIView. For instance:

myView.backgroundColor = [UIColor blueColor];

Make sure your view has been created, and if it is controlled by xib or storyboard in general, make sure that the view is already loaded (otherwise everything that is set in the interface builder will become the background color). If this does not work, something strange happens. Keep looking, this post will not help you.

Original post:

I have an NSObject with a UIView property. I mainly use this UIView to display an image, but in some cases I want to set its background color. However, every time I try to set the background color, the color remains the same sharp. Any images or other sub-items appear, but there is no background. How to change background color of UIView? Here is my code:

here is an example where I need a tiled image: (this is in the function called after adding the UIView to the viewcontroller)

(image is a UIView property)

 picture.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Tile.png"]];

I also tried in other cases:

picture.backgroundColor = [UIColor colorWithRed:0 green:1 blue:1 alpha:0.5];

In both cases, the background remains clear.

+5
source share
7 answers

, , , , , , , , . .

0

UIView, ? , , , UIView, .

:

picture = [[UIView alloc] initWithFrame:CGRectMake(10,10,200,200)];
picture.backgroundColor = [UIColor redColor];

, iVar UIView .

+7

alpha 0,0 1,0. 50, 1:

picture.backgroundColor = [UIColor colorWithRed:0 green:1 blue:1 alpha:1];
+2

RGB,

picture.backgroundColor = [UIColor colorWithRed:0 green:1 blue:1 alpha:1];

UIColor, backgound

picture.backgroundColor = [UIColor greenColor];
+1

, , . ( ), .

0

. "".

0

, . , picture.opaque YES ( , ). , . . , :

    NSLog(@"Frame size: width=%f, height=%f", picture.frame.size.width, picture.frame.size.height);

-1
source

All Articles