UILABEL이 3 줄 이상을 표시 할 수 없습니다
-
13-09-2019 - |
문제
나는 많은 세포가있는 탁자를 가지고 있으며 Uilabel이 3 줄 이상을 표시하도록하려고합니다. LineBreakMode와 NumberOfLines를 적절하게 설정했지만 여전히 3 줄 이상 표시되지 않습니다. 제안이 있습니까? 테이블 셀은 chars/라인의 수를 수용하기 위해 높이를 자동으로 조정하지만 텍스트는 3 줄과 타원을 보여줍니다 (셀을 클릭하면 전체 텍스트를 표시하는 다른보기로 이동합니다.
아래는 uilabel을 작성하고 표시 해야하는 코드입니다.
self.commentLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:12.0 bold:YES];
self.commentLabel.textAlignment = UITextAlignmentLeft; // default
self.commentLabel.lineBreakMode = UILineBreakModeWordWrap;
self.commentLabel.numberOfLines = 0; // no limit to the number of lines
[myContentView addSubview:self.commentLabel];
[self.commentLabel release];
전체 주석을 테이블 셀에 표시하고 싶습니다.
해결책
라벨의 사각형이 너무 작아 모든 텍스트에 맞지 않는 것 같습니다 ... 타원을 표시하지 않고 전체 텍스트를 표시하려면 사각형을 더 크게 만들어야합니다.
다른 팁
Autolayout Design 개념을 사용하여 Uilabel의 높이 제약 조건을 설정하지 말고 NO를 설정하십시오. 0으로 줄입니다.
Autolayout은 레이블의 텍스트에 따라 자동으로 레이블의 동적 높이를 관리합니다. 레이블에 한 줄 텍스트가 있으면 단일 줄 공간 만 차지합니다. 레이블에 한 줄 이상이 있으면 텍스트 크기와 텍스트를 표시하는 데 필요한 줄 수에 따라 레이블을 크기로 조정합니다.
- TableView DataSource 및 Delegate를 할당하고 구현하십시오
- 양수인
UITableViewAutomaticDimension
RowHeight & ExtrowHeight에 - 대의원/데이터 소스 방법을 구현하십시오 (즉
heightForRowAt
그리고 값을 반환합니다UITableViewAutomaticDimension
그것에)
-
목표 C :
// in ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property IBOutlet UITableView * table;
@end
// in ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.table.dataSource = self;
self.table.delegate = self;
self.table.rowHeight = UITableViewAutomaticDimension;
self.table.estimatedRowHeight = UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
이 답변을보십시오. UITIBLEVIEWCELL 내에서 UILABEL을 동적으로 조정 하시겠습니까?
제휴하지 않습니다 StackOverflow