Change border width of label in custom UICollectionCell - ios

I have custom UICollectionViewCell and I have placed 2 UILabels in it. Now I want to change the borderRadius and borderWidth of the labels in it. Can anyone tell me how to do this?
I am doing in this way, but nothing is happening:
self.titleLabel.layer.borderWidth = 2.0;
self.titleLabel.layer.borderColor = [UIColor blackColor].CGColor;
I am putting these two lines in initWithFrame method.

If you want to set the borderWidth of UILabel inside means why you are using
self.titleLabel.layer.borderWidth = 2.0;
Instead of this you can directly use the label name like,
yourLabel1.layer.borderWidth = 2.0;
yourLabel2.layer.borderWidth = 2.0;
Like wise you can change the borderRadius also.

With the following line added the border should appear:
self.titleLabel.layer.masksToBounds = YES;

Related

Make UISwitch border width smaller

Hello I am trying to make UISwitch borderWidth smaller, but it doesn't look correct.
All I did is
layer.borderWidth = 0.5
instead of using storyboard try to customise switch programmatically . try using following code as if you change one parameter must adjust radius of switch too. Hope it helps
OnOffSwitch.layer.borderWidth = 1.0;
OnOffSwitch.layer.cornerRadius = 16.0;
OnOffSwitch.layer.borderWidth = 0.5;
OnOffSwitch.layer.cornerRadius = 17.0;

iOS: Image is not displaying properly in UIImageView

I have a UIImageView in which a UIImage is showing which comes from JSON. The problem is that I want to set the cornerRadius for the UIImageView. I put the following code for it:
imgVw.layer.cornerRadius = 30.0;
imgVw.layer.borderWidth = 2.0;
imgVw.layer.borderColor = [UIColor blackColor].CGColor;
It displays the cornerRadius and border for UIImageView but not in the proper way. The image is showing outside the corners like in screenshot.
You need to set the masksToBounds property of layer to YES like this
self.imgVw.layer.masksToBounds = YES;
Set the clipsToBounds property of UIImageView to YES.
Like
set imgVw.clipsToBounds=YES;

How to get a circle image in UIImageView

I tried to get a circle image using layer, here is my code
_compassArrow.layer.cornerRadius = _compassArrow.frame.size.width / 2;
_compassArrow.layer.masksToBounds = YES;
_compassArrow.layer.borderColor = [UIColor whiteColor].CGColor
the compassArrow is an imageview which display the compass image. And when I run my program, it looks terrible:
my actual picture
I don't know what happened to it. I've add some constraints to it, to make it has equal width with the device. Does this influence my image?
I think you set cornerRadius before your constraints are applied. Try to put this code in layoutSubviews or viewDidLayoutSubviews for example.
This way, the _compassArrow.frame.size.width value will be the one after constraints applied on it, and you'll get the correct cornerRadius.
Here is a piece of code that should allow you to do this.
_compassArrow.layer.borderWidth = 1.0
_compassArrow.layer.masksToBounds = false
_compassArrow.layer.borderColor = UIColor.whiteColor().CGColor
_compassArrow.layer.cornerRadius = profilePicture.frame.size.width/2
_compassArrow.clipsToBounds = true

Tableview: Add a shadow

My designer asked me to add a shadow to the cell of my tableview like this:
Currently I have implemented everything functional, even the Top | Latest header-view. How can I add such a shadow to the end of each tableviewsection?
Below is my solution. In this situation don't forget to set your view's backgroundColor even it's whiteColor and shadowOpacity.
And give an extra space around your cellSubView to show the shadow.
You can set appropriate values instead of mines depending on your requirements.
Hope this helps.
cellSubView.backgroundColor = [UIColor whiteColor];
cellSubView.layer.shadowColor = [UIColor blackColor].CGColor;
cellSubView.layer.shadowOpacity = 0.5;
cellSubView.layer.shadowOffset = CGSizeMake(0,10);
cellSubView.layer.shadowRadius = 3;

Custom Rounded Button without Corner Radius

how do we subclass a UIbutton and customize it so that it has a round end like this one on Periscope. The Following Button.
I would like to PREVENT using layer.CornerRadius though.
Using a BezierPath perhaps? but I have a math problem creating the Path.
Any thoughts? Thank you
I have created that button using the layer.CornerRadius as below :-
self.buyButton.layer.cornerRadius = self.buyButton.frame.size.height/2;
self.buyButton.clipsToBounds = YES;
[UPDATED CODE - FOR SHADOW]
self.buyButton.layer.masksToBounds = NO;
self.buyButton.layer.borderWidth = 1.0f; //Just for look n feel
self.buyButton.layer.shadowColor = [UIColor greenColor].CGColor;
self.buyButton.layer.shadowOpacity = 0.8;
self.buyButton.layer.shadowRadius = 12;
self.buyButton.layer.shadowOffset = CGSizeMake(12.0f, 12.0f);
But why u don't want to use the method already provided as per your custom requirement I don't think you need to use bezier path for this.
UPDATED SCREENSHOT :

Resources