問題描述
標籤邊框內的間距 (spacing inside label's border)
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?
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];
‑‑‑‑‑
參考解法
方法 1:
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
方法 2:
Have you tried this‑
NSString *text = [NSString stringWithFormat:@"\n\n%@%@%@\n\n",@" ",[[self.DtlArray objectAtIndex:indexPath.row] objectForKey:@"comment"],@" "];
方法 3:
You may create a custom view and
‑ (void)drawRect:(CGRect)rect {
......;
[string drawInRect:rect withFont:font lineBreakMode:mode alignment:ali];
......;
}
hope that helps
(by Nithin M Keloth、user1824262、Rahul Wakade、Daniel Gao)