9
votes

I need to draw a rounded rectangle bar in my iOS application, but without using a background image. Is there any way to make a rounded rectangle view or label?

4
hey first Ravi has answered your question.check it. - Tendulkar

4 Answers

30
votes

In addition to the other answer(s), don't forget to set the masksToBounds property.

#import <QuartzCore/QuartzCore.h>

label.layer.cornerRadius = 5.0;
label.layer.masksToBounds = YES;
5
votes

Alternative if you're using the UI designer (Storyboard or nib file) you can set a User Defined Runtime Attribute.

Click on the view you want to have rounded corners, click Show the Identity Inspector (3rd tab, top right). Then click the + in User Defined Runtime Attributes and enter the following:

Key Path: layer.cornerRadius
Type: Number
Value: whatever number, e.g. 5
4
votes

Add Quartz core Framework ..

#import <QuartzCore/QuartzCore.h>

Then Set corner radius,

yourView_LabelName.layer.cornerRadius = 10.0;
2
votes

It may be useful for you. Step1 :add the quartzcore framework to your project frameworks. In which file you want to write this code there, you have to use this.

        #import <QuartzCore/QuartzCore.h>
        UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 50, 30)];
        myLabel.text = @"text";
        myLabel.layer.cornerRadius =8.0;
        [self.view addSubview:myLabel];