标题图像在可展开表中不可调整大小



我对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;
}

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

我没有

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

//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 中进行。

确保调整视图的大小,十确保在正确的位置调整视图的大小。

相关内容

  • 没有找到相关文章

最新更新