0

友達、私はボーダー付きのUILabelを作成しました(下の画像のように)。

1 行または 2 行を残してからラベルを開始し、ラベルの最後の行を終了してから 1 行または 2 行下に再度ラベルを付けたいと考えています。

ラベルの境界内に間隔を空ける方法はありますか?

これはボーダー付きの 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 に答える