标签边框内的间距

时间:2012-11-21 13:42:50

标签: iphone objective-c ios xcode uilabel

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

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

有没有办法在标签的边框内留出间距?

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 个答案:

答案 0 :(得分:2)

使当前标签(commentLabel)颜色为白色。创建另一个具有相同内容和更小尺寸的标签,将其放置在边框内。按照您的意愿制作填充

答案 1 :(得分:0)

Have you tried this-

      NSString *text = [NSString stringWithFormat:@"\n\n%@%@%@\n\n",@"  ",[[self.DtlArray  objectAtIndex:indexPath.row] objectForKey:@"comment"],@" "];

答案 2 :(得分:0)

您可以创建自定义视图和

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

希望有所帮助