1

I am taking text to UILabel which is inside a UItableViewCell(label text is coming from webData-so it varies in size).

I want to give a border for my label, which should fit the text width and height. I have created one, but it's not looking good.
Help me to improve my code.

**Also is there any way to get border with rounded corners ? **

Hey I am getting text inside the border like this, and the corners are not so rounded:

enter image description here

UILabel *cmntBoxlbl = [[UILabel alloc]initWithFrame:CGRectMake(58, 23, 250, 60)];
cmntBoxlbl.font=[UIFont fontWithName:@"Arial" size:12];
cmntBoxlbl.layer.borderColor = [UIColor darkGrayColor].CGColor;
cmntBoxlbl.layer.borderWidth = 1.0;
NSString *text = [NSString stringWithFormat:@"%@%@%@",@"  ",[[self.DtlArray objectAtIndex:indexPath.row] objectForKey:@"comment"],@" "];
cmntBoxlbl.text = text;



cmntBoxlbl.textAlignment = UITextAlignmentCenter;
cmntBoxlbl.lineBreakMode = UILineBreakModeWordWrap;
[cmntBoxlbl setTextColor:[UIColor darkGrayColor]];

CGSize expectedLabelSize = [text sizeWithFont:cmntBoxlbl.font
                            constrainedToSize:cmntBoxlbl.frame.size
                                lineBreakMode:UILineBreakModeWordWrap];

CGRect newFrame = cmntBoxlbl.frame;
newFrame.size.height = expectedLabelSize.height;
cmntBoxlbl.frame = newFrame;
cmntBoxlbl.numberOfLines = 0;
[cmntBoxlbl sizeToFit];
[cell addSubview:cmntBoxlbl];
2
  • oh you again...thanks issue is that,text inside the border is disorder text is coming i have posted the screen shot below And also i have to make rounded corners Nov 21, 2012 at 9:24
  • +1 for a well explained question.
    – Midhun MP
    Nov 21, 2012 at 10:10

2 Answers 2

3

*also is there any way to get border with rounded corners ?? *

#import <QuartzCore/QuartzCore.h>
label.layer.borderWidth = 3;
label.layer.borderColor = [[UIColor blackColor] CGColor];
label.layer.cornerRadius = 5;
0
2

For rounded corner set.

[cmntBoxlbl.layer setCornerRadius:15];

Also add the QuartzCore framework and import the header:

#import <QuartzCore/QuartzCore.h>

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.