分享

设置UITableVIewCell 缩进,只有文字缩进 图片不动的解决方法

 永恒clek4xeu0r 2017-01-26

设置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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约