2013-01-31 32 views
0

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

很抱歉,如果這是一個簡單的問題,你的幫助是非常感謝!

回答

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內。

確保您正在調整正確視圖的大小,確保您在正確的位置調整大小。

+0

非常感謝你!我試圖調整不是在單元格中的imageView框架,非常愚蠢的 – luliger

+0

你能否幫我解決另一個問題,再簡單一點。如何爲不同的頭文件創建不同的圖片? – luliger

+0

你有你的數組,你正在填充你的tableview。只要基於該數組中的某個條件來做一個條件語句。說如果我的數據說什麼'UIImage * myImage = [UIImage imageNamed:@「someImage];',否則,如果我的數據說別的東西'UIImage * myImage = [UIImage imageNamed:@」somethingElse];' – Putz1103