Draw border "within" UIViewController - ios

I need to draw a visible border that goes around the edge of the screen within my view controller. I tried setting the view's borderWidth and borderColor, but nothing appeared on the screen. How would I accomplish this?

I tried the following code and it worked.
self.view.layer.borderColor = UIColor.orangeColor().CGColor
self.view.layer.borderWidth = 3

Related

Make a UIView with a blurred view as borderColor

I need to create a UIView with a blurred view as borderColor.
How can I get that to work?
I have attached a sample image as an example of my requirement.
Thanks
I don't think the border of a UITextField has a fading property, or anything similar. However, with a bit of work, you can accomplish what you need:
1) Download/acquire a background image that has the border you want. It can be rectangular. Add it to your project.
2) In IB, set the BorderStyle of you TextView to None, the BackgroundImage to the image you added, and add an outlet to your UIViewController class.
3) Add the following code to your viewDidLoad. Replace with the name of your IBOutlet:
<textField>.layer.cornerRadius =5.0
This should give you a UITextField with rounded corners and your background image. You may have to play around with your image and the cornerRadius values to get exactly what you want, but the code should work.
Use my code its work perfectly. Textviewview is my One UIView and inside it one textfield and one UIImageview i use.
Textviewview.layer.cornerRadius = 25.0
Textviewview.layer.shadowColor = UIColor(white: 0.0, alpha: 0.5).CGColor
Textviewview.layer.shadowOffset = CGSizeMake(0.0, 0.0)
Textviewview.layer.shadowOpacity = 1.0
Textviewview.layer.shadowRadius = 6.0

Add "shadow" to view

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;

Working with transparency: View behind transparent view should only shine through and not overlap

I'm currently working with transparency and I'd like to have the following effect:
As you can see the line takes the full width of the view. There are some transparent UIViews also on this screen. The line seems to be below the transparent UIView and if it overlaps it has another color, because of the transparent UIView above. When there is no overlapping the line get its normal color.
How can I get this effect?
I tried to set the background of the UIView to transparent, but it didn't helped. The line has its normal color and doesn't interact with the transparency. Furthermore I tried to change the transparency of the view itself but with the same wrong result.
The rectangle above is done with code
UIView rectangle = new UIView (new CGRect (10, 10, 200, 120));
rectangle.BackgroundColor = UIColor.FromRGBA (204,115,225, 50);
UIView line = new UIView (new CGRect (0, 105, 320, 1));
line.BackgroundColor = UIColor.Red;
View.AddSubview (line);
View.AddSubview (rectangle);
line.SendSubviewToBack (rectangle);
the rectangle below is created in iOS designer.
Am I missing something?
Its all about the z order of the Subviews.
line.SendSubviewToBack (rectangle);
is probably not what you want.
If you add the line with its normal red color and add a UIView that has its alpha dropped to e.g. 0.5, then you should get the effect you want.
The z-order of the subviews was correct in my case. Depending on the color the effect I want is possible or not. So I made the following:
Choose another background color for the lavender color rectangles and adapt the alpha transparency to look similar. So something like this:
rectangle.BackgroundColor = UIColor.FromRGBA (245/255.0f,227/255.0f,249/255.0f,0.7f);

UIView border cover sub-view?

I have a UIView which includes a UIButton which is partially on UIView. I have a problem when I draw a border on my UIView. Please have a look at my screenshot:
You can see the border is above the UIButton, why? Can anybody suggest? Thanks
Thanks for aăâ, I found a solution.
Basically the border is always drawn on top of everything
What I did is:
Create a UIView with color of border
Create another UIView as the child the main UIView which is a little bit smaller than the first one. The color of this newly create UIView is the main color
Here is the code:
self.layer.cornerRadius = 15;
self.layer.masksToBounds = YES;
self.backView.layer.cornerRadius = 15;
self.backView.layer.masksToBounds = YES;
The result is:
It's more or less what I need although it's not perfect.
It could have to do with the order that the objects are drawn. In your storyboard's "Document Outline", views that are lower down in a view controller's outline are drawn later. Perhaps the button is not the last drawn view, like you want?

Using UIColor tiled images as the background of a view doesn't work with cornerRadius

I have used UIColor colorWithPatternImage to get a tiled color. I set this as the background of my view. After this, any changes to view.layer.cornerRadius do not have any affect: it doesn't change the corner radius. I have also tried adding another subview to my view, setting that's background color to the pattern and using cornerRadius on my view to no avail.
How can I fix this behaviour?
Thanks for your time.
Set the clipsToBounds of the view to YES and it should work. I had the same issue.
Here is my snippet:
self.leftPanelView.layer.cornerRadius = 10;
self.leftPanelView.clipsToBounds = YES;
self.leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"linePattern_gray.png"]];
which shows the linePattern_gray.png as the background patterned with a nice rounded corner.

Resources