朋友, 我創建了一個帶邊框的UILabel(就像下圖所示)。標籤邊界內的間距
我想在離開一行/兩行後再開始我的標籤,然後在標籤的最後一行再次下一行/兩行之後開始標籤。
有沒有辦法讓標籤的邊界內部有空格?
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];
感謝rahul ...它爲第一行空間工作 但是在文本之後,這不起作用 我意思是在最後一行之後沒有空間低於 –
我試過了,它適用於我。結果只有一行是空白的。嘗試在下面提供更多空行,例如: NSString * text = [NSString stringWithFormat:@「\ n \ n \ n」,@「」,[[self.DtlArray objectAtIndex: indexPath.row] objectForKey:@「comment」],@「」]; –