我正嘗試用邊框,部分頁眉和單元格創建UITableview。我正在使用xib文件。 UITableview和使用xib文件創建的單元格,其中「viewForHeaderInSection」用於區域標題,但是當我嘗試將邊框設置爲UITableview時,它隱藏了區域和單元格。 UITableview邊框隱藏部分單元格
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.tableView.delegate = (id) self;
self.tableView.dataSource = (id) self;
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
self.tableView.layer.borderWidth = 20.0;
self.tableView.layer.borderColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0f].CGColor;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
NSDictionary *dict = [[NSDictionary alloc] initWithDictionary:[self.array objectAtIndex:section] copyItems:YES];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 5, tableView.frame.size.width, 50)];
view.backgroundColor = [UIColor colorWithRed:81/255.0 green:190/255.0 blue: 168/255.0 alpha:1.0f];
UIView *seperatoreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 10)];
seperatoreView.backgroundColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0f];
[view addSubview:seperatoreView];
UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
numberLabel.backgroundColor = [UIColor clearColor];
numberLabel.text = [NSString stringWithFormat:@"%@",[dict objectForKey:@"key"]];
numberLabel.textColor = [UIColor whiteColor];
[numberLabel setFont:[UIFont boldSystemFontOfSize:17.0f]];
[view addSubview:numberLabel];
NSDateFormatter *formate = [[NSDateFormatter alloc] init];
[formate setDateFormat:@"yyyy-MM-dd"];
NSDate *SDate = [formate dateFromString:[dict objectForKey:@"sDateKey"]];
NSDate *EDate = [formate dateFromString:[dict objectForKey:@"eDateKey"]];
[formate setDateFormat:@"MMM d"];
NSString *StartDateStr = [formate stringFromDate:SDate];
NSString *EndDateStr = [formate stringFromDate:EDate];
if([StartDateStr isEqual:[NSNull null]]){
StartDateStr = @"";
}
if([EndDateStr isEqual:[NSNull null]]){
EndDateStr = @"";
}
UILabel *weekDateLabel = [[UILabel alloc] initWithFrame:CGRectMake(view.frame.size.width-140, 10, 150, 30)];
weekDateLabel.backgroundColor = [UIColor clearColor];
weekDateLabel.text = [NSString stringWithFormat:@"%@ - %@",StartDateStr,EndDateStr];
weekDateLabel.textColor = [UIColor whiteColor];
[weekDateLabel setFont:[UIFont boldSystemFontOfSize:17.0f]];
[view addSubview:weekDateLabel];
return view;
}
我想UITableView的邊框,但與全斷面頭部和單元,難道有誰知道如何實現的呢?
能否請您分享您的代碼? – Kampai
做一件事。我不知道這是正確的答案。但試試吧。增加邊框高度的大小並在章節標題底部設置標籤。我們可以自定義節標題。一個代表方法就在那裏。 – phani
你可以做更多的事情來避免這個問題。將tableView的邊框顏色設置爲背景顏色或tableView的父視圖,並根據邊框寬度填充左邊距。這樣,你可以避免這個問題。 – Surjeet