gpt4 book ai didi

ios - 我正在尝试缩进表格 View 单元格文本标签的右边距

转载 作者:行者123 更新时间:2023-11-29 01:00:14 25 4
gpt4 key购买 nike

我使用以下代码使单元格从左侧缩进:

[cell setIndentationWidth:1];
[cell setIndentationLevel:15];

不幸的是,当单元格包含大量文本时,这会偏移 TableView 单元格文本标签,所以这里的问题是省略号是文本标签的内容更靠右,并且在缩进时省略号比平时显示得更远从左边开始。

如何让我的 UITableViewCelltextLabel 也有正确的缩进(或边距)?

最佳答案

我做了以下操作(似乎您不能以任何其他方式设置文本标签的框架)。

header (.h):

@interface UITableViewCellFixed : UITableViewCell

@property (nonatomic, assign) CGRect textLabelFrame;

@end

实现(.m):

@implementation UITableViewCellFixed : UITableViewCell

- (id)initWithLabelFrame:(CGRect)textLabelFrame {
self = [super init];
if (self)
self.textLabelFrame = textLabelFrame;
return self;
}

- (void) layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = self.textLabelFrame;
}

@end

...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
UITableViewCellFixed *cell = [[UITableViewCellFixed alloc] initWithLabelFrame:CGRectMake(30, 0, tableView.frame.size.width - 60, 50)];
...
}

关于ios - 我正在尝试缩进表格 View 单元格文本标签的右边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37102255/

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