objective-c - 修复UILabel的边框

标签 objective-c ios xcode uitableview uilabel

我正在向 UILabel 发送短信在 UItableViewCell 内(标签文本来自 webData,因此大小不同)。

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

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

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

enter image description here

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];

最佳答案

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

#import <QuartzCore/QuartzCore.h>
label.layer.borderWidth = 3;
label.layer.borderColor = [[UIColor blackColor] CGColor];
label.layer.cornerRadius = 5;

关于objective-c - 修复UILabel的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13489875/

相关文章:

objective-c - block 在异步线程上执行两次

objective-c - NSString 替换正则表达式

ios - Objective-C 错误 "Expected identifier or ' (' "

ios - 单击搜索栏中的输入按钮后,如何更新 View Controller 以显示搜索结果?

objective-c - 如何将日期+时间保存和检索到 sqlite3 数据库中?

ios - 在多个 UITextField 的数字键盘上显示完成按钮

JavaScript doOnOrientationChange :can't fix a bug loading the page

ios - Xcode 中的事件监视器显示

ios - 在 Objective-C 的内存管理上下文中,哪个是定义常量的最佳选择?

swift - 如何在 UITableVIew 的不同单元格中使用 UITextView 获取用户输入