0

朋友们,我创建了一个带边框的 UILabel(如下图所示)。

我想在剩下一/两行之后开始我的标签,然后在完成最后一行标签之后再次在下面一/两行。

有没有办法在标签的边框内获得间距?

这是带有边框的 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];
4

3 回答 3

2

使当前标签(commentLabel)颜色为白色。创建另一个具有相同内容和较小尺寸的标签,将其放置在边框内。根据需要进行填充

于 2012-11-27T16:36:47.517 回答
0
Have you tried this-

      NSString *text = [NSString stringWithFormat:@"\n\n%@%@%@\n\n",@"  ",[[self.DtlArray  objectAtIndex:indexPath.row] objectForKey:@"comment"],@" "];
于 2012-11-21T13:55:57.813 回答
0

您可以创建自定义视图并

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

希望有帮助

于 2012-11-21T17:01:35.017 回答