I am giving border to UILabel with
Label.text = lbltext;
Label.layer.borderColor = [[UIColor grayColor] CGColor];
Label.layer.borderWidth = 2;
But There is no space between text and border.
so how can i set inset effect like UIButton in my Label?
Put the label in a container view and apply the border to the container.
You can subclass UILabel, and override a couple of methods:
The first gives you rounded corners and a border. You can tweak the border width, color etc. as needed.
- (void)drawRect:(CGRect)rect
{
self.layer.cornerRadius = 4.0;
self.layer.borderWidth = 1;
[super drawRect:rect];
}
The second lets you specify insets to position the label text away from the left border.
- (void) drawTextInRect:(CGRect)rect
{
UIEdgeInsets insets = {0,5,0,5};
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With