2012-05-05 61 views
0

我正在編寫一個包含RSS閱讀器的應用程序。 rss閱讀器正在下載標題,說明和圖像。我將該圖像放置在與說明相同的單元格中的輔助視圖中。描述放置在文本標籤中,並完全調整圖像大小。但我希望圖像顯示在左側。但是,當我從accessoryview中刪除圖像並將其移動到左側的圖像時,T​​extlabel不會調整其大小。如何在tableview單元格中調整textlabel的大小

如何調整文本標籤大小。

CGRect f = cell.textLabel.frame; 
[cell.textLabel setFrame: CGRectMake(f.origin.x-20, f.origin.y, f.size.width-50, f.size.height)]; 

cell.textLabel.font = [UIFont systemFontOfSize:11]; 
cell.textLabel.numberOfLines =3; 
cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7]; 
cell.backgroundColor = [UIColor clearColor]; 
cell.textLabel.backgroundColor = [UIColor clearColor]; 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 

我試圖用setframe函數調整它的大小,但是這不起作用。

希望有些人可以推動我走向正確的方向。

在此先感謝

回答

2

您需要繼承UITableViewCell類。這裏有一個例子:

.h文件中:

#import <UIKit/UIKit.h> 

@interface MyCustomerCell : UITableViewCell 

@end 

.m文件:

#import "MyCustomerCell.h" 

@implementation MyCustomerCell 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

- (void)layoutSubviews { 
    [super layoutSubviews]; 
    self.imageView.frame = CGRectMake(0,0,150,90); 
    self.imageView.bounds = CGRectMake(0, 0, 150, 90); 
    self.textLabel.frame = CGRectMake(250, 0, 200, 40); //change this to your needed 
    self.detailTextLabel.frame = CGRectMake(250, 40, 200, 40); 
} 

@end

+0

我怎麼然後實現它在我的tableview? –

+0

在你有tableview的類中: 1.導入頭文件:#import「MyCustomerCell.h」。 2.您定義單元格的任何地方使用:MyCustomerCell * cell = ...而不是正常的UITableViewCell * cell = ... – user523234

+0

感謝伴侶 - 那關心我的問題:) –

相關問題