1

我正在获取UILabel位于 a 内的UItableViewCell文本(标签文本来自 webData,因此它的大小会有所不同)。

我想给我的标签一个边框,它应该适合文本的宽度和高度。我已经创建了一个,但看起来不太好。
帮助我改进我的代码。

**还有什么办法可以得到圆角的边框?**

嘿,我在边框内收到这样的文字,而且角落不是那么圆润:

在此处输入图像描述

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

2 回答 2

3

*还有什么办法可以得到圆角的边框??*

#import <QuartzCore/QuartzCore.h>
label.layer.borderWidth = 3;
label.layer.borderColor = [[UIColor blackColor] CGColor];
label.layer.cornerRadius = 5;
于 2012-11-21T09:22:58.547 回答
2

用于圆角设置。

[cmntBoxlbl.layer setCornerRadius:15];

还要添加QuartzCore框架并导入标头:

#import <QuartzCore/QuartzCore.h>

于 2012-11-21T09:23:50.650 回答