ios - How do I add an image to the UITableViewHeaderFooterView? -
can me figure out how add , image header view? code tried using doesn't work. below have far.
- (void)tableview:(uitableview *)tableview willdisplayheaderview:(uiview *)view forsection:(nsinteger)section { uitableviewheaderfooterview *headerview = (uitableviewheaderfooterview*)view; if (headerview != nil) { headerview.contentview.backgroundcolor = [uicolor greencolor]; uiimageview *imageview = [[uiimageview alloc] initwithframe:cgrectmake(200.0f, 0.0f, 100.0f, 25.0f)]; *imageview.image = [uiimageview = image.png];* //this line doesn't work. [headerview.contentview addsubview:imageview]; uilabel *mainlabel = [[uilabel alloc] initwithframe:cgrectmake(0.0f, 0.0f, 100.0f, 25.0f)]; mainlabel.text = [sectiontitles objectatindex:section]; mainlabel.backgroundcolor = [uicolor redcolor]; [headerview.contentview addsubview:mainlabel]; uilabel *secondlabel = [[uilabel alloc] initwithframe:cgrectmake(0.0f, 26.0f, 150.0f, 20.0f)]; secondlabel.text = @"second label text"; secondlabel.backgroundcolor = [uicolor yellowcolor]; [headerview.contentview addsubview:secondlabel]; } }
please try this
- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { uiimage *aimage = [uiimage imagenamed:@"myheaderimage.png"]; uiimageview *aimgview = [[uiimageview alloc] initwithimage:aimage]; aimgview.frame = cgrectmake(5, 5, 310, 60); return aimgview; }
Comments
Post a Comment