gpt4 book ai didi

ios - 如何在表格 View 单元格中调整文本标签的大小

转载 作者:行者123 更新时间:2023-11-28 22:57:53 24 4
gpt4 key购买 nike

我正在编写一个包含 RSS 阅读器的应用程序。 rss 阅读器正在下载标题、描述和图像。我放在与描述相同的单元格中的附件 View 中的图像。说明放在文本标签中,并根据图像完美调整大小。但我希望图像显示在左侧。但是当我从附件 View 中删除图像并将其移动到左侧的图像时,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);
}

@结束

关于ios - 如何在表格 View 单元格中调整文本标签的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10463970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com