Wednesday, 12 October 2011

Header & Footer View on UITableview


Header and Footer on tableview.
( Less Overhead on UItableviewCell )


-(void) viewDidLoad {
//Calling this on viewdidload Nothing to do on CellForRowAtIndexPath

self.tableView.tableHeaderView = [self headerView];
self.tableView.tableHeaderView = [self footerView];
}


//Header

-(UIView *) headerView{

UIView *customView=[[UIView alloc]initWithFrame:CGRectMake(10,3,290,40)];
UILabel *lblUnlistedStore = [[UILabel alloc] initWithFrame:CGRectMake(16,3,290,35)];
lblUnlistedStore.backgroundColor = [UIColor clearColor];
lblUnlistedStore.font=[UIFont boldSystemFontOfSize:14.0];
lblUnlistedStore.lineBreakMode=UILineBreakModeWordWrap;
lblUnlistedStore.numberOfLines=3;
lblUnlistedStore.textColor=kBlueColor;
lblUnlistedStore.text=@"YOUR_TEXT";
[customView addSubview:lblUnlistedStore];
return customView;


}

//Footer
-(UIView *) footerView{
UIView *customView=[[UIView alloc]initWithFrame:CGRectMake(5,3,290,120)];
UIButton *btnStorePhone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnStorePhone.frame = CGRectMake(5,3,140,35);
[btnStorePhone setTitle:@"7838657511" forState:UIControlStateNormal];
btnStorePhone.titleLabel.textColor = [UIColor bluecolor];
[btnStorePhone addTarget:self action:@selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:btnStorePhone];

UIButton *btnStoreWebsiteURL = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnStoreWebsiteURL.frame = CGRectMake(160,3,140,35);
btnStoreWebsiteURL.titleLabel.textColor = [UIColor bluecolor];
[btnStoreWebsiteURL setTitle:@"Visit Website" forState:UIControlStateNormal];
[btnStoreWebsiteURL addTarget:self action:@selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];

[customView addSubview:btnStoreWebsiteURL];

UILabel *lblStoreHours = [[UILabel alloc] initWithFrame:CGRectMake(10,50,290,60)];
lblStoreHours.layer.cornerRadius=10.0; // this is for styling your label i.e. to give oval shape to your label.It needs Quartz core framework to be included. 
lblStoreHours.layer.masksToBounds=YES;


lblStoreHours.font=[UIFont systemFontOfSize:14.0];
lblStoreHours.lineBreakMode=UILineBreakModeWordWrap;
lblStoreHours.numberOfLines=3;

lblStoreHours.text=@"YOUR_TEXT";

[customView addSubview:lblStoreHours];
return customView;


}

Cheers :)

No comments:

Post a Comment