【问题标题】:I am trying to indent the right margin of my table view cell's text label我正在尝试缩进我的表格视图单元格的文本标签的右边距
【发布时间】:2016-05-08 16:42:49
【问题描述】:
我使用下面的代码使单元格从左侧缩进:
[cell setIndentationWidth:1];
[cell setIndentationLevel:15];
不幸的是,当单元格包含大量文本时,这会偏移表格视图单元格文本标签,所以这里的问题是省略号是文本标签的内容更靠右,并且在缩进时省略号显示得比平时更远从左边开始。
如何让我的UITableViewCell 的textLabel 也有右缩进(或边距)?
【问题讨论】:
标签:
ios
objective-c
uitableview
margins
【解决方案1】:
我做了以下(似乎你不能以任何其他方式设置文本标签的框架)。
标题(.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)];
...
}