After setting border width and corner radius of UIView getting black circular line
Code:
afterSelectFrameView.layer.borderWidth=[slide value];
afterSelectFrameView.layer.cornerRadius=[slide value];
Apply mask to bounds
[imageView.layer setMasksToBounds:YES];
[imageView.layer setCornerRadius:5.0];
setting the border is not necessary, but here is an option for you.
[imageView.layer setBorderWidth:0.0f];
I use the code below (it is part of a ViewUtilities library) to round the corners on any view.
You could modify it to add parameters for other radii, colors, etc.
+(void)AdjustViewEdges:(UIView*)view
{
[view.layer setBorderColor: [[UIColor blackColor] CGColor]];
[view.layer setBorderWidth: 1.0];
[view.layer setCornerRadius:12.0f];
[view.layer setMasksToBounds:YES];
view.backgroundColor = [UIColor colorWithRed:.99 green:0.99 blue:0.99 alpha:1.0];
}
// You will need this as well
#import <QuartzCore/QuartzCore.h>
I don't believe it is giving me the lines you are seeing...but my background colors were different so they may be hidden...
Was this helpful?
Use it like this
afterSelectFrameView.layer.borderWidth=0.0;
afterSelectFrameView.layer.cornerRadius=[slide value];
Happy coding..........
Related
I know there are similar questions out there, but haven't found an answer that has helped me resolve my issue. If you've seen one, feel free to mark this as duplicate, but please make sure it answers the entire question and not just similar parts.
I have a UIImageView, and I am rounding the corners and adding a border to it. However, I'm starting to add some drop shadows to give my UI some depth. I'm adding a shadow to my profile picture, and the following code works great for a perfectly square image, which gets cropped into a perfect circle. However, for non-square rectangular images, the shadow is applied to the image itself rather than the image view, so I end up with a round border around a cropped rectangular image, which has a shadow around the edges that don't reach the circular border. Any insight into how I can modify my code to apply this shadow to be around the border, instead of the image within the UIImageView?
Thanks
//Set profile image view to be rounded (default appears rounded due to alpha background, need rest to appear rounded as well
[self.profileImageView layoutIfNeeded];
CALayer *imageLayer = self.profileImageView.layer;
[imageLayer setCornerRadius:self.profileImageView.frame.size.width/2];
[imageLayer setBorderWidth:1];
[imageLayer setBorderColor:[[UIColor colorWithRed:78.0/255.0 green:82.0/255.0 blue:85.0/255.0 alpha:1] CGColor] ];
[imageLayer setMasksToBounds:YES];
//Apply shadows to necessary views for the job badge
[self.profileImageView.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.profileImageView.layer setShadowRadius:4.0f];
[self.profileImageView.layer setShadowOffset:CGSizeMake(0, -3)];
[self.profileImageView.layer setShadowOpacity:0.5f];
The problem is that shadow is masked together with other content when you set cornerRadius.
You can use an intermediate conteiner view with shadow and masked imageView inside. Here is the code, but you can do the same with Interface Builder and autolayouts as well:
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
[containerView.layer setShadowColor:[[UIColor blackColor] CGColor]];
[containerView.layer setShadowRadius:4.0f];
[containerView.layer setShadowOffset:CGSizeMake(0, -3)];
[containerView.layer setShadowOpacity:0.5f];
[self.view addSubview:containerView];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:containerView.bounds];
imageView.image = [UIImage imageNamed:#"rgb"];
[imageView.layer setCornerRadius:imageView.frame.size.width/2];
[imageView.layer setBorderWidth:1];
[imageView.layer setBorderColor:[[UIColor colorWithRed:78.0/255.0 green:82.0/255.0 blue:85.0/255.0 alpha:1] CGColor] ];
[imageView.layer setMasksToBounds:YES];
[containerView addSubview:imageView];
Output:
To achieve the above design I use the below code. Every thing is perfect.
for(....)
{
CALayer *layer=[CALayer layer];
[layer setFrame:CGRectMake(xAxis, 2.0f, width, height)];
[layer setBackgroundColor:[self getColor:colorId]];
[[self layer] addSublayer:layer];
}
I have use cornerRadious for rounding the corner. And the problem is on corners it's shows the background colours little bit. Can anybody please suggest me what to do. I am using below code for cornerRadious. Thanks in advance.
[[vBarHolder layer] setCornerRadius:3.0f];
[[vBarHolder layer] setBorderColor:[[UIColor whiteColor] CGColor]];
[[vBarHolder layer] setBorderWidth:2.0f];
[[vBarHolder layer] setMasksToBounds:YES];
[vBarHolder setClipsToBounds:YES];
Your coloured views are overlapped by vBarHolder.
Modify the code as below.
for(....)
{
CALayer *layer=[CALayer layer];
[layer setFrame:CGRectMake(xAxis + 2, 2.0f + 2, width - 4 , height- 4)];
[layer setBackgroundColor:[self getColor:colorId]];
[[self layer] addSublayer:layer];
}
as the layers are having corner radius as 0 you are able to see in background.
Regards,
Amit
I'd like to add a border to a TVC cell's image through the imageView and the imageView layer
I've got code that works for the cell.layer itself, but as soon as I change it to the cell.imageView.layer, the code does nothing at all.
I'm using it within tableView:cellForRowAtIndexPath and am in Xcode 4.6.3, iOS 6.x
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.imageView.image = [UIImage imageNamed:#"myImage.png"];
CALayer* layer;
//layer = cell.layer;
layer = cell.imageView.layer;
[layer setMasksToBounds:YES];
[layer setCornerRadius:10.0f];
[layer setBorderWidth:10.0f];
This works if applied to cell.layer, but does nothing at all to the cell's imageView.layer.
Any ideas?
Thanks.
EDIT: FYI, I am importing <QuartzCore/QuartzCore.h>.
EDIT: though this works against the cell just fine, that is because the cell already has a border color defined as black. The imageView does not and therefore requires a border color to be set like so:
[cell.imageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[cell.imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[cell.imageView.layer setBorderColor: [[UIColor colorWithRed:.5f green:.6f blue:.3f alpha:.75f] CGColor ]];
Another option is, add
#import <QuartzCore/QuartzCore.h>
FrameWork and use
cell.imageView.layer.borderWidth = 1.0f;
cell.imageView.layer.setMasksToBounds = YES;
Though this code works against the cell just fine, that is because the cell already has a border color defined as black. The imageView does not and therefore requires a border color to be set like so:
[cell.imageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[cell.imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[cell.imageView.layer setBorderColor: [[UIColor colorWithRed:.5f green:.6f blue:.3f alpha:.75f] CGColor ]];
How do I create a white border and black shadow for my UIImageView?
Just import
#import <QuartzCore/QuartzCore.h>
and make sure that you have the QuartzCore framework added to your project.
Then to add border
[imageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
To create shadow, see this SO question, which will get you going..
this is the way I add a border and shadow to an UIImage in a UIMageView
someImageView.image = someUIImage;
someImageView.frame = CGRectMake(45, 25, 50, 50);
[someImageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[someImageView.layer setBorderWidth: 2.0];
[someImageView.layer setShadowOffset:CGSizeMake(-3.0, 3.0)];
[someImageView.layer setShadowRadius:3.0];
[someImageView.layer setShadowOpacity:1.0];
remember:
#import <QuartzCore/QuartzCore.h>
You can just add it as another UIImageView behind the one showing your image.
I am using a uitableview and scrollview in a uiview. How to set a border for table or scrollview?
#import "QuartzCore/QuartzCore.h"
then in viewDidLoad use,
tableView.layer.borderWidth = 2.0;
Note
You can also set the border color:
tableView.layer.borderColor = [UIColor redColor].CGColor;
It should work for you. :)
This works quite well for me:
CALayer *layer = _tableView.layer;
[layer setMasksToBounds:YES];
[layer setCornerRadius: 4.0];
[layer setBorderWidth:1.0];
[layer setBorderColor:[[UIColor colorWithWhite: 0.8 alpha: 1.0] CGColor]];
The rounded borders look a little more iOS.
if you want to give the border to tableview with color, use below code
for swift 3
yourTableViewName.layer.borderColor = UIColor.gray.cgColor
yourTableViewName.layer.borderWidth = 1.0