내 구역 위의 텍스트가 너무 길어서 잘리지 않습니다.titleForHeaderInSection 텍스트가 너무 깁니다.
은 오래 두 행을 만들기 같이이 문제를 해결하기 위해 어떤 방법?
도움이 되셨다면
내 구역 위의 텍스트가 너무 길어서 잘리지 않습니다.titleForHeaderInSection 텍스트가 너무 깁니다.
은 오래 두 행을 만들기 같이이 문제를 해결하기 위해 어떤 방법?
도움이 되셨다면
를 참조하십시오. 모든 머리글 높이를 모든 행에 대해 충분히 큰 값으로 수정하거나 특정 머리글에 대해 필요한 높이를 계산할 수 있습니다 (아래 참조). viewForHeaderInSection`https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView : 대리자 '를 tableView에
let headerFont:UIFont = UIFont.systemFontOfSize(14);
let headerTexts = ["one line", "two line test123 sadfjklsadf asdjfklasjdflk asdfjklasdjfl asdfjklsadf"];
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2;
}
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return heightOfHeaderText(headerTexts[section]);
}
func heightOfHeaderText(text:String) -> CGFloat{
return NSString(string: text).boundingRectWithSize(
CGSizeMake(self.tableView.frame.size.width, 999),
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: [NSFontAttributeName : headerFont],
context: nil).size.height;
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerLabel:UILabel = UILabel.init(frame: CGRectMake(0, 0, tableView.frame.size.width, self.tableView(tableView, heightForHeaderInSection: section)));
headerLabel.numberOfLines = 0;
headerLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping;
headerLabel.font = headerFont;
headerLabel.text = headerTexts[section];
return headerLabel;
}
라벨이있는 사용자 정의보기를 만드십시오. viewForHeaderInSection 대리자 메서드를 사용하여 해당 레이블에 텍스트를 할당하고이 뷰를 반환합니다.
편집 :
이 링크 당신은heightForHeaderInSection
을 정의하고
viewForHeaderInSection
을 사용자 정의해야
Customize UITableView header section
약간의 시간을 주시겠습니까? 더 많은 정보 무엇을해야합니까? – Cing
수정 사항보기 ... –
에 응답 : viewForHeaderInSection : 다중 행 레이블 서브 뷰가있는 더 큰 뷰를 반환하십시오. – danh
[Customize UITableView header section] (http://stackoverflow.com/questions/15611374/customize-uitableview-header-section) –