0

Friends, i have created a UILabel with border (just like the image below).

I want to start my label after one/two lines left and then after finishing last line of label again one/two lines below.

Is there any way to get spacing inside label's border?

This is the UILabel with border

 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]; 

3 Answers 3

2

Make current label(commentLabel) color is white. create another label with same content and a little smaller size,place it inside the boarder.Make padding as you wish

Sign up to request clarification or add additional context in comments.

Comments

0
Have you tried this- NSString *text = [NSString stringWithFormat:@"\n\n%@%@%@\n\n",@" ",[[self.DtlArray objectAtIndex:indexPath.row] objectForKey:@"comment"],@" "]; 

2 Comments

thanks rahul...its working for the first line space But after the text,this is not working I mean after last line there is no space below
I tried it & it works for me. Only the thing is at the end only one line is blank. Try giving more blank lines at below like- NSString *text = [NSString stringWithFormat:@"\n\n%@%@%@\n\n\n",@" ",[[self.DtlArray objectAtIndex:indexPath.row] objectForKey:@"comment"],@" "];
0

You may create a custom view and

- (void)drawRect:(CGRect)rect { ......; [string drawInRect:rect withFont:font lineBreakMode:mode alignment:ali]; ......; } 

hope that helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.