Is it possible to show something under clipped area?
For example I have:
UIView *viewA = ...
viewA.layer.cornerRadius = radius;
viewA.layer.masksToBounds = YES;
So, here I have view with rounded corners. Then I want to add another viewB as subview of viewA and present it under clipped area of viewA. Help me, please, how can I do that?
You mean that you want viewB to be clipped too or that it is shown in the clipped area?
If it is the former:
viewA.clipsToBounds = YES;
UIView *viewB = ...
viewB.frame = ... // something relative to viewA.bounds
[viewA addSubview:viewB];
EDIT:
Then for what you want to do you have to set viewA.clipsToBounds = YES, create a container view for both viewA and viewB and put them both as subviews of this container. You can't clip a superview and have an unclipped subview.
Related
I have cells with 2 "rectangles". What i want is, add shadow to right rectangle. It will be better explained on screenshot:
From left is first part of cell (first rectangle) and on a right in second part. I want to add a shadow that look like on a screenshot. I tried:
-(void)addInnerShadow{
self.bgDetailsView.layer.shadowColor = [UIColor colorWithHexString:#"#a4c2e0"].CGColor;
self.bgDetailsView.layer.shadowOffset = (CGSize){SHADOW_SIDE_HEIGHT,0};
// self.vSelectionBack.layer.shadowRadius = 1.4;
self.bgDetailsView.layer.shadowRadius = SHADOW_SIDE_HEIGHT;
self.bgDetailsView.layer.shadowOpacity = .5;
}
Where bgDetailsView is second (right) view, but it has no effect.
Ok, so as I understand you want to add shadow to right view and shadow casts over the left view.
To do so:
You can set self.bgDetailsView.clipsToBounds = NO, it will make shadow visible but will also make your shadow to be visible over and below the right view.
You can put right view in container. Set clipsToBounds = NO in right view and make container view a bit bigger to the left.
You can also make a container view with additional CALayer or UIImageView with shadow image. Put your right view to right of this additional view/layer and set in container clipsToBounds = NO.
You can also use shadowPath property of right view layer and put it in container view:
self.bgDetailsView.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowRect].CGPath;
I want to add a "shadow" image on my view, but, i want part of my view to still be "visible". You better understand what i want to do, when look on screenshot:
I can add a UIView above my superview, but how could i make specific point "visible"? That actually mean make specific area of a view with different colour or opaque.
For your problem I had a way, try the below example.
1. First storyboard design: I had a UIButton
2. Added black View as a subview
UIView *blackView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
blackView.backgroundColor=[UIColor blackColor];
blackView.alpha=0.6f;
[self.view addSubview:blackView];
now result will be:
3. Add one more UIImageView with frame equal to button frame
UIImageView *imageView=[[UIImageView alloc]init];
imageView.frame=self.button.frame; //getting current UIButton bounds
imageView.image=[UIImage imageNamed:#"add_img.png"];
[self.view addSubview:imageView];
Now it looks same as what you want:
You have to add some views. A main view will be the container of your less-alpha view and of the opaque button.
MainView
|
------- UIView with 0.6 alpha
|
------- UIButton with 1 alpha
Indeed, if you change the alpha of the MainView, all subviews will be affected. Here, UIView with 0.6 will have the same frame as MainView but it will not affect UIButton alpha.
Make a new View, a parent View with clear color background. Add the black view and the button to the parent view and set the black view's alpha to 0.6 or whatever.
Try this:
Make a UIView called buttonBackgroundView, give it a black color and then
[self.view addsubView:buttonBackgroundView];
now make a UIView named plusView (or UIButton if this plus sign is a button) then
[self.view addsubView:plusView];
After that, give the alpha to the buttonBackgroundView
buttonBackgroundView.alpha = 0.6;
Happy coding!
The following print screen shows my layout:
I have the main view , then a Top view and then a picture.
When I press on the picture, I want a semi transaprent black screen appearing on the entire view:
let scrennRect = UIScreen.mainScreen().bounds
let coverView = UIView(frame: scrennRect)
coverView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
self.view.addSubview(coverView)
But I want my picture to stay on top of the coverView ?
Is there a way I can bring only the picture to be in front of the coverView ?
The problem is that your coverView and imageView have different super views.
That's why you cannot bring the imageView to the front.
In order to bring the imageView to the front you need to move it outside of the Top View so your View contains the Top view and the imageView.
Then, you can add the coverView to the main view, and bring the imageView to the front.
Another solution:
Place an image view inside the coverView at the exact same position.
This should do your work. Any view maintains a stack of its subviews.
self.view.addSubView(blackTransparentView);
self.view.bringSubViewToFront(myImageView);
iOS view hierarchies are doing my head in - I want to achieve something that should be basic.
In a UIWebView I want to center a UIActivityIndicatorView with a UILabel below it in the middle of the UIWebView. The activity indicator and the label can be considered as children of another UIView - and it's that parent UIView that needs to be centered in the UIWebView
How does one go about this? How do you get the frame of the parent UIView to be the bounding rect of it's children?
Both views should be sub views of a super view...
UIView *activityView = //the view with the label and activity indicator...
UIView *webView = //the web view...
activityView.center = webView.center;
Done :)
I have a view that is slightly translucent, I set the alpha to about .75 and it contains a button as a sub element.
I want the button to be completely opaque and I set the opaque property in IB but still the button appears as translucent.
Any pointers?
Thanks!
A subview of a superview is allways minimum as transparent as its subview.
Subview alpha = 0.5 and superview alpha = 0.1 would result in an alpha of the subview of 0.05.
The only way of achieving that is changing the view hierarchy. Your subview must not be a subview any more. It may still be at the same position. (May require different position value).
An example.
Your background view is backgroundView
Your superview is firstView
Your subview is overlayView
Your current hierarchy is
backgroundView -> firstView -> overlayView
You should change that to:
backgroundView -> first View
\-> overlay View.
If your firstView's position is (10, 10) and your overlayView's position was (20,20) then change your overlayView's position to (30,30) because it now is within the coordinate system of background view.
For your code:
At some point you used to have
[backgroundView addSubView:firstView];
[fisrtView addSubView:overlayView];
change that to
[backgroundView addSubView:firstView];
[backgroundView addSubView:overlayView];
If you did not code that but defined it within IB then just move overlayView within the views tree accordingly so that it is on the same level as firstView.
Regardless whether you code it or draw it in IB, make sure that firstView comes first and overlayView comes next. Otherwise firstView could hide overlayView when its alpa is greater than 0.