페이지

2012년 8월 3일 금요일

UITableView custom header


// 커스텀 헤더
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
    UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)];
    //headerView.contentMode = UIViewContentModeScaleToFill;
    
    // Add the label
    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, -5.0, 300.0, 90.0)];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    NSString *sessionNo = [[NSUserDefaults standardUserDefaults] objectForKey:@"MySessionNo"];
    headerLabel.text = sessionNo;
    headerLabel.textColor = [UIColor blackColor];
    headerLabel.highlightedTextColor = [UIColor blackColor];
    
    //this is what you asked
    headerLabel.font = [UIFont boldSystemFontOfSize:17];
    
    headerLabel.shadowColor = [UIColor clearColor];
    headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
    headerLabel.numberOfLines = 0;
    headerLabel.textAlignment = UITextAlignmentCenter;
    [headerView addSubview: headerLabel];
    
    [headerLabel release];  
    
    // Return the headerView
    return headerView;
}

댓글 없음:

댓글 쓰기