设置UITableVIewCell 缩进,只有文字缩进 图片不动的解决方法 解决方法: 新建一个UITableViewCell的子类 :ChildTableViewCell 重写- (void)layoutSubviews方法 - (void)layoutSubviews
{
[super layoutSubviews];
CGRect frame = self.imageView.frame;
frame.origin.x = self.indentationLevel*self.indentationWidth;
self.imageView.frame = frame;
}
在tableView的cellForRow里加载刚才创建的UITableViewCell的子类
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID = @'cell';
ChildTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[ChildTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
// 屏幕适配
CGFloat indentationLevel = ANScreenWidth / 26;
cell.indentationLevel = indentationLevel;
}
ANLog(@'%zd', indexPath.row);
NSArray *titles = @[@'Home', @'Settings', @'Profile'];
NSArray *images = @[@'IconHome', @'IconProfile', @'IconSettings'];
cell.textLabel.text = titles[indexPath.row];
cell.imageView.image = [UIImage imageNamed:images[indexPath.row]];
return cell;
}
参考地址 http:///questions/21645356/ios-7-uitableviewcell-setindentationlevel-did-not-apply-for-imageview http:///questions/15924412/uitableviewcell-imageview-padding http:///questions/19080039/ios7-uitableviewcell-image-left-offset |
|
来自: 永恒clek4xeu0r > 《ios》