简体   繁体   English

如何在tableview单元格中调整textlabel的大小

[英]how to resize textlabel in a tableview cell

I'm programming an app that is containing a RSS reader. 我正在编写一个包含RSS阅读器的应用程序。 The rss reader is downloading a title, description and a image. rss阅读器正在下载标题,描述和图像。 The image I placed in the accessoryview in the same cell as the description. 我在附件视图中放置的图像与描述相同。 The description is placed in a textlabel and resize perfectly to the image. 描述放在文本标签中,并完美地调整图像大小。 But i would like the image to be displayed in the left side. 但我希望图像显示在左侧。 But when i remove the images from the accessoryview and move it to the image to the left side the Textlabel doesn't resize. 但是当我从附件视图中删除图像并将其移动到左侧的图像时,T​​extlabel不会调整大小。

How do i resize the 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;

I have tried to resize it with the setframe function but that doesn't work. 我试图用setframe函数调整它的大小,但这不起作用。

Hope there are some of you that can push me in the right direction. 希望你们中的一些人能够把我推向正确的方向。

Thanks in advance 提前致谢

You need to subclass the UITableViewCell class. 您需要子类化UITableViewCell类。 Here is an example: 这是一个例子:

.h file: .h文件:

#import <UIKit/UIKit.h>

@interface MyCustomerCell : UITableViewCell

@end

.m file: .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 @结束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM