标头图像在可扩展表中无法调整大小

时间:2013-01-31 16:05:15

标签: ios iphone xcode uitableview expandable

我是Xcode的新手,这个简单的问题让我很生气!我创建了一个可扩展的表,工作正常。这是UIView子类的一些代码,用于在您点击单元格时展开的部分:

- (id)initWithFrame:(CGRect)frame WithTitle: (NSString *) title Section:(NSInteger)sectionNumber delegate: (id <SectionView>) Delegate
{
self = [super initWithFrame:frame];
if (self) {

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(discButtonPressed:)];
    [self addGestureRecognizer:tapGesture];

    self.userInteractionEnabled = YES;

    self.section = sectionNumber;
    self.delegate = Delegate;

    CGRect LabelFrame = CGRectMake(100, 100, 100, 100);
    LabelFrame.size.width -= 100;
    CGRectInset(LabelFrame, 1.0, 1.0);

    //BUTTON 
    CGRect buttonFrame = CGRectMake(LabelFrame.size.width, 0, 100, LabelFrame.size.height);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = buttonFrame;
    //[button setImage:[UIImage imageNamed:@"carat.png"] forState:UIControlStateNormal];
    //[button setImage:[UIImage imageNamed:@"carat-open.png"] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(discButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    self.discButton = button;

    //My IMAGE
    NSString *imageName = @"gradient1.png";
    UIImage *myImage = [UIImage imageNamed:imageName];
    UIImageView *sectionHeaderView = [[UIImageView alloc] initWithImage:myImage];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
    imageView.frame = CGRectMake(20,50,100,100);
    [self addSubview:sectionHeaderView];
    self.headerBG = sectionHeaderView;

    //HEADER LABEL
    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(22, 12, sectionHeaderView.frame.size.width, 35.0)];
    label.textAlignment = NSTextAlignmentLeft;
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor darkGrayColor];
    label.shadowOffset = CGSizeMake(0.0, -1.0);
    label.text = title;
    label.font = [UIFont fontWithName:@"AvenirNext-Bold" size:20.0];
    sectionHeaderView.backgroundColor = [UIColor clearColor];
    //label.textAlignment = UITextAlignmentLeft;
    [self addSubview:label];
    self.sectionTitle = label;
}

return self;
}

我在单元格@“gradient1.png”上有自定义图像,但我似乎无法调整大小?这是UITableViewController中的头代码:

    - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:   (NSInteger)section
  {
SectionInfo *array  = [self.sectionInfoArray objectAtIndex:section];
if (!array.sectionView)
{
    NSString *title = array.category.name;
    array.sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0, 10, self.tableView.bounds.size.width, 0) WithTitle:title Section:section delegate:self];
}
return array.sectionView;
}

很抱歉,如果这是一个微不足道的问题,非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我没有看到你在哪里试图调整图像的大小,所以我无法提供任何帮助,为什么它没有调整大小,但我发现这令人困惑:

//My IMAGE
    NSString *imageName = @"gradient1.png";
    UIImage *myImage = [UIImage imageNamed:imageName];
    UIImageView *sectionHeaderView = [[UIImageView alloc] initWithImage:myImage];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
    imageView.frame = CGRectMake(20,50,100,100);
    [self addSubview:sectionHeaderView];
    self.headerBG = sectionHeaderView;

在这部分代码中,您创建了两个图像视图,然后调整一个并将另一个添加到单元格(我假设单元格)子视图。您是否可能尝试调整从未添加为单元格子视图的视图的大小?

此外,调整大小应在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath内进行。

确保您正在调整正确的视图大小,10确保您在适当的位置调整大小。