Created
March 4, 2016 07:03
-
-
Save wisaruthk/1b6522394fc05a6ef6d6 to your computer and use it in GitHub Desktop.
iOS custom uitableview header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section | |
{ | |
if(tableView==self.tableView1){ | |
CGRect frame = tableView.frame; | |
//NSLog(@"self view %@",NSStringFromCGRect(self.view.frame)); | |
//NSLog(@"tableview frame %@",NSStringFromCGRect(frame)); | |
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 20)]; | |
CGFloat btnWidth = 50; | |
CGFloat btnTrail = 10; | |
UIButton *sortButton = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width-(btnWidth+btnTrail), 0, btnWidth, 20)]; | |
sortButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; | |
[sortButton setTitle:LocalizedString(@"Sort") forState:UIControlStateNormal]; | |
sortButton.backgroundColor = [UIColor redColor]; | |
[sortButton addTarget:self action:@selector(sortIngdPopup:withEvent:) forControlEvents:UIControlEventTouchUpInside]; | |
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)]; | |
title.text = LocalizedString(@"Ingredients"); | |
//UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; | |
headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; | |
[headerView addSubview:sortButton]; | |
return headerView; | |
} else { | |
CGRect frame = tableView.frame; | |
//NSLog(@"self view %@",NSStringFromCGRect(self.view.frame)); | |
//NSLog(@"tableview frame %@",NSStringFromCGRect(frame)); | |
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 20)]; | |
CGFloat btnWidth = 50; | |
CGFloat btnTrail = 10; | |
UIButton *sortButton = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width-(btnWidth+btnTrail), 0, btnWidth, 20)]; | |
sortButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; | |
[sortButton setTitle:LocalizedString(@"Sort") forState:UIControlStateNormal]; | |
sortButton.backgroundColor = [UIColor redColor]; | |
[sortButton addTarget:self action:@selector(sortNtPopup:withEvent:) forControlEvents:UIControlEventTouchUpInside]; | |
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)]; | |
title.text = LocalizedString(@"Nutrient Specs"); | |
//UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; | |
headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; | |
[headerView addSubview:sortButton]; | |
return headerView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment