私はこのcolor sliderを私のアプリケーションに組み込みました。テーブルビューのセルに収まるように問題を抱えているので、両方のポートレートでセルの長さが必要ですおよびランドスケープビュー。以下は私のアプリを縦横に見せる2つのスクリーンショットです。カラースライダがセルの全長に及ばないことがわかります。ここで私のコードは、色のスライダを設定します。私はどのようにCGRectをコードするプロパティを把握しようとしているので、カラースライダが動的にセルの長さを塗りつぶします。テーブルビューのセルのカラースライダをセルの全長に設定
func configureColorSlider() {
let colorSlider = ColorSlider()
let xCell = colorCell.contentView.bounds.width
let yCell = colorCell.contentView.bounds.height
colorSlider.frame = CGRect(x: xCell/4, y: yCell/4, width: 200, height: 24)
colorSlider.orientation = .horizontal
colorSlider.addTarget(self, action: #selector(ConfigureTimestampTableViewController.changedColor(_:)), for: .valueChanged)
colorCell.contentView.addSubview(colorSlider)
}
EDIT ご提案から、私は以下の私のコードを更新しました。これは、縦向きの場合に効果的です。カラースライダは、カラーラベルの右側にあるセルのフルサイズを占めます。ただし、電話機を横向きに回転させると、カラースライダは画面の半分しか塗りつぶしません。以下は、それがどのように見えるかのスクリーンショットです。
func configureColorSlider() {
let colorSlider = ColorSlider()
let xCell = colorCell.contentView.bounds.width
let yCell = colorCell.contentView.bounds.height
colorSlider.frame = CGRect(x: xCell/4, y: yCell/4, width: 200, height: 24)
colorSlider.orientation = .horizontal
colorSlider.addTarget(self, action: #selector(ConfigureTimestampTableViewController.changedColor(_:)), for: .valueChanged)
colorCell.contentView.addSubview(colorSlider)
colorSlider.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([colorSlider.leadingAnchor.constraint(equalTo: colorLabel.trailingAnchor, constant: 8),
colorSlider.trailingAnchor.constraint(equalTo: colorCell.contentView.trailingAnchor, constant: -8),
colorSlider.topAnchor.constraint(equalTo: colorCell.contentView.topAnchor, constant: 8),
colorSlider.bottomAnchor.constraint(equalTo: colorCell.contentView.bottomAnchor, constant: -8) ])
}
お返事ありがとうございます。私はこれを試みたが、それは私のアプリをクラッシュさせている。これを達成するために自動レイアウトを使用すべきであるという意味合いがあります。私はコードで遊んでいきます。 – chickenparm
私が提供したコードは、完全なコードを見ずにコードを伝えるのは難しい例です。クラッシュするとどんなエラーが出ますか?あなたはストーリーボードを使用していますか? – AlexanderKaran
私はストーリーボードを使用しています。上記の質問を、あなたの提案から試したコードで更新しました。お手伝いありがとう! – chickenparm