uiview with uiimage as background - iphone

u build an UIView and put an image as the view backgrond:
self.tmpView = [[UIView alloc] initWithFrame:CGRectMake(20, 70, 280, 295)];
self.tmpView.backgroundColor = [UIColor yellowColor];
self.tmpView.backgroundColor = [UIColor clearColor];
self.tmpView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"CloseUPPicBG.png"]];
the problem is that theuiview is now with corners in black color.
the image that i put as backgrond is with rounded corners.
any solution for this?

Edit the image to not have rounded corners, or so that the space behind the corners is some other color or image.
What you're doing is saying
View, be yellow.
View, be clear. What's behind you? Nothing. Ok, be black.
View, fill yourself with this image.
View is then thinking
Hmm... there's transparency in this image.
Guess I should show whatever's behind me. Which is nothing... So black.

self.tmpView.opaque = NO;
might help.

Related

Subview appears underneath superviews layer.border?

I have a UIView in which I define it's border in the following manner:
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.borderWidth = 3;
I attach a subview to this UIView, and when I move the subview over the border, it goes underneath it. Is this the intended behavior? Is there anyway to make the subview go on top of it?
According to the Apple specification: It is composited above the receiver’s contents and sublayers.
So, the border will always be above of all your subviews, even if you bring your subview to the front and so on.
So I make a background view to fake the border.
E.g.:
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
backgroundView.backgroundColor = [UIColor blackColor];
backgroundView.clipsToBounds = NO;
UIView *bView = [[UIView alloc] initWithFrame:CGRectInset(backgroundView.bounds, 3, 3)];
bView.backgroundColor = [UIColor redColor];
UIView *cView = [[UIView alloc] initWithFrame:CGRectMake(-50, -50, 100, 100)];
cView.backgroundColor = [UIColor yellowColor];
[bView addSubview:cView];
[backgroundView addSubview:bView];
[self.window addSubview:backgroundView];
and the effect:
Depending on your view structure, it might be easier to add the subview to the parent of your main view. It can then overlap the main view and will overlay the border as you requested.
Did you try setting the superview's 'clipsToBounds' property to YES? This is set to NO by default for performance reasons, but setting it to yes might give you the effect you are looking for.
Insert layer at specific position that suits you:
self.layer.insertSublayer(sublayer, at: 0)

How to fill the part of the imageview with another color

I am developing an application in which I am using one UIImageView and adding one rectangle image to that UIImageView. I am getting some float value from another calculation like 67.4 and I need to place one green image on the 67.4 part of rectangle UIImageView. So please tell me how can I fill that green image onto that UIImageView ?
You can make a "rectangle", i.e. a UIView and color it as you wish. Then add it to your image view.
UIView *greenRect = [[UIView alloc] initWithFrame:
CGRectMake(67.4, 67.4, width, height)];
greenRect.backgroundColor = [UIColor greenColor];
[imageView addSubview:greenRect];

UItextview Transparent Color IOS

I want to set my UItextview s color transparent but not completely transparent. I want little bit gray or black at the background exactly like the picture
I am using this code right now
_textView.backgroundColor = [UIColor clearColor];
how can I make it transparent like in the picture above? Any example Code?
You should use something like this:
_textView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5];
where alpha - parameter for transparent ( 50% in example).
Does this do what you want? (You may need to experiment with the values).
_textView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];

Clear Background color on UIImageView?

hello i have a UIimageView with a PNG image that has round corners, image sits fine the only problem it has is that i can see the UIImage Corners with a white background, how can I make the background clear and transparent.
Try this:
imageView.backgroundColor = [UIColor clearColor];
imageView.opaque = NO;
You can achieve the same thing in IB by making the 'Background' a color with 0% opacity, and unticking the 'Opaque' checkbox.
try
imageView.backgroundColor = [UIColor clearColor];

Change background color/image of TTThumbsViewController

can I change the background image of my TTThumbsViewController. It's the thumbnail overview screen and at the moment it is white. Can I turn it to transparent?
Thx :-)
(void)viewDidLoad {
self.tableView.backgroundColor = [UIColor blackColor];
}