ios - 我如何将宽度设置为自定义 UITableViewCell

标签 ios uitableview swift2 width cell

我想将自定义 UITableViewCell 的宽度设置为屏幕宽度的 80%,但我知道单元格的大小可以使用“layoutSubviews()”方法进行操作,但我不知道如何操作。

请帮帮我。

最佳答案

答案太简单了。只需更改类中单元格的框架即可。

class CustomCell: UITableViewCell {


    override var frame: CGRect {
        get {
            return super.frame
        }
        set (newFrame) {
            var frame = newFrame
            let newWidth = frame.width * 0.80 // get 80% width here
            let space = (frame.width - newWidth) / 2
            frame.size.width = newWidth
            frame.origin.x += space

            super.frame = frame

        }
    }

}

关于ios - 我如何将宽度设置为自定义 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765594/

相关文章:

ios - Swift 和 HealthKit : type of expression too ambiguous without more context

ios - 突出显示 UIAlertView 中的单词? (加粗文字)

ios - ScrollView Autolayout 中的 TableViews

iphone - iOS 错误选择器错误

ios - 展开/折叠 UITableview

ios - 无法将值类型 'TableViewController.Type' 转换为预期的参数类型 'UIViewController'

ios - 首次使用或应用进入后台时下载失败

ios - 如何获取Tableview中指定行的IndexPath?

ios - 网站未在 UIWebView 中加载

ios - 无法将类型 'Swift.UInt64' (0x10dddde88) 的值转换为 'Swift.AnyObject' (0x12129d018)