I want to do some thing like this,
How to draw a circle in UILabel which looks similar to this image, i just want to avoid using an image instead.
I'd suggest adding a shape layer to the UILabel. Something like this:
// Create the shape layer
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 50, 50)].CGPath;
circleLayer.fillColor = [UIColor clearColor].CGColor;
circleLayer.strokeColor = [UIColor whiteColor].CGColor;
circleLayer.lineWidth = 1;
// Add it do your label's layer hierarchy
[label.layer addSublayer:circleLayer];
That'll give you the greatest control over its appearance and that of the font for the A.
UPDATE:
It's just occurred to me that you'll struggle to get the "A" vertically offset in order to put a circle around it. There are hacks to get vertical centering in a UILabel, but you'd be much better off using a UITextField instead, since it supports the contentVerticalAlignment property. You just need to set its userInteractionEnabled to NO to prevent user from typing text on it!
Other than that, the principle of adding the CAShapeLayer is the same.
You can achieve this by the way @maddy suggested or, create UILabel
with square rect, put text alignment to the middle and use label's layer's cornerRadius
with borderWidth
. Just set cornerRadius
to the half width (or height) of the label. Good Luck!
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