Iphone: put uiimage in tableview section header, stretching problem

Hey people, I put UIImage in the section header of my UITableVIew. So I used the code that I found on the Internet:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

self.imageViewForImage.image = [helperClass resizeImage:[self.offerItem objectForKey: @"picture"] forSize:CGSizeMake(280.0, 280.0) ];

[self.imageViewForImage.layer setBorderColor: [[UIColor blackColor] CGColor]];
[self.imageViewForImage.layer setBorderWidth: 1.2];

self.imageViewForImage.contentMode = UIViewContentModeBottom;
return self.imageViewForImage;}


-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
        return 320;
    return 1.0;
}

At first, the image was fully scaled over the entire width of the iphone with a size of 320 pixels. But then I found out that all of my UITableView contentMode property was set to "UIViewContentModeScaleToFill". So I added a line of code that tells my UIImageView not to scale. In my case, I set it to "UIViewContentModeBottom".

Problem: it all works, the image is finally shown in an aspected size of 280x280, BUT the border that I made around the picture is still stretched / resized to the full width of the iphone ...?!

, , UIImage.

.

edit: - , ?

+5
1

UIImageView , . imageView, . , contentMode , , , . , (, , ) - , .

, , UIImageView. :

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] init];

    self.imageViewForImage.frame = CGRectMake(20, 20, 280, 280);
    self.imageViewForImage.image = [self.offerItem objectForKey:@"picture"];
    self.imageViewForImage.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

    [self.imageViewForImage.layer setBorderColor: [[UIColor blackColor] CGColor]];
    [self.imageViewForImage.layer setBorderWidth: 1.2];

    [headerView addSubview:self.imageViewForImage];
    return [headerView autorelease];
}

, !

: , , , tableView . , .

+9

All Articles