簡體   English   中英

如何在tableview單元格中調整textlabel的大小

[英]how to resize textlabel in a tableview cell

我正在編寫一個包含RSS閱讀器的應用程序。 rss閱讀器正在下載標題,描述和圖像。 我在附件視圖中放置的圖像與描述相同。 描述放在文本標簽中,並完美地調整圖像大小。 但我希望圖像顯示在左側。 但是當我從附件視圖中刪除圖像並將其移動到左側的圖像時,T​​extlabel不會調整大小。

我如何調整文本標簽的大小。

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函數調整它的大小,但這不起作用。

希望你們中的一些人能夠把我推向正確的方向。

提前致謝

您需要子類化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);
}

@結束

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM