2012-11-21 3 views
1

UItableViewCell 안에있는 UILabel (텍스트가 webData에서오고 있으므로 크기가 다양 함)로 문자를 가져갑니다.UILabel에 경계선 고정

내 레이블에 테두리를주고 싶습니다. 텍스트의 너비와 높이에 맞춰야합니다. 나는 하나를 창조했으나 좋지 않다.
코드 개선에 도움.

** 둥근 모서리로 테두리를 가져 오는 방법이 있습니까? **

이봐, 난이 같은 경계 내부에 텍스트를 얻고, 그리고 모서리 그렇게 반올림되지 않습니다

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

문제가 무엇입니까? –

+0

오 다시 ... 감사 문제는 경계 내부에 텍스트가 장애 텍스트 내가 아래의 스크린 샷을 게시 한 그리고 잘이 질문을 설명하기위한도 내가 둥근 모서리 –

+0

일을해야 오고있다,는 것이다. –

답변

2

둥근 모서리 세트의 경우.

[cmntBoxlbl.layer setCornerRadius:15]; 

또한 QuartzCore 프레임 워크를 추가하고 헤더를 가져옵니다

#import <QuartzCore/QuartzCore.h>

3

을 * 또한 둥근 모서리와 국경을 얻을 수있는 방법이있다? ? *

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