最新消息:20210917 已从crifan.com换到crifan.org

[已解决]swift中tableView中的cell的textLabel设置对齐

Swift crifan 1685浏览 0评论

已有代码:

            cell.textLabel?.text = "查看资料"
            cell.textLabel?.textColor = textColor
            cell.textLabel?.font = textFont
           
            cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

现在希望:

给textLabel添加约束,使得左边对齐一定间距

swift uitableviewcell textlabel

swift uitableviewcell textlabel constraint

swift uitableviewcell textlabel padding

swift table view cell textlabel

然后直接加上约束就可以了:

let XPaddingAllPage:CGFloat = 15.0
            cell.textLabel?.text = "查看资料"
            cell.textLabel?.textColor = textColor
            cell.textLabel?.font = textFont
           
            cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
           
            constrain(cell.textLabel!) { textLabel in
                textLabel.left == textLabel.superview!.left + XPaddingAllPage
                textLabel.centerY == textLabel.superview!.centerY
            }

就实现了对齐的效果:

转载请注明:在路上 » [已解决]swift中tableView中的cell的textLabel设置对齐

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
94 queries in 0.207 seconds, using 23.61MB memory