Xcode10.1を利用していて、掲題Failed to render and update auto layout status forというエラーが発生し、storyboard上でも青枠だけの表示となりつまづいております。
他のサイトを調べ、Derived Dataを削除したり、Podfileをアップデート、Clean bundle等をしてもダメな様です。@IBDesignableを利用してるクラスは下記なのですがご教示頂けますと幸いです。
import UIKit
@IBDesignable class RatingControl: UIStackView {
private var ratingButtons = [UIButton]() var rating = 0{ didSet { updateButtonSelectionStates() }
}
@IBInspectable var starSize: CGSize = CGSize(width: 44.0, height: 44.0){ didSet{ setupButtons() } } @IBInspectable var starCount: Int = 5{ didSet{ setupButtons() } } override init(frame: CGRect) { super.init(frame: frame) setupButtons() } required init(coder: NSCoder) { super.init(coder: coder) setupButtons() } /* // Only override draw() if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func draw(_ rect: CGRect) { // Drawing code } */ @objc func ratingButtonTapped(button: UIButton){ guard let index = ratingButtons.index(of: button) else { fatalError("The button, (button), is not in the ratingButtons array: (ratingButtons)") } // Calculate the rating of the selected button let selectedRating = index + 1 if selectedRating == rating { // If the selected star represents the current rating, reset the rating to 0. rating = 0 } else { // Otherwise set the rating to the selected star rating = selectedRating } } private func setupButtons() { for button in ratingButtons { removeArrangedSubview(button) button.removeFromSuperview() } ratingButtons.removeAll() let bundle = Bundle(for: type(of: self)) bundle.loadNibNamed(String(describing: self), owner: self, options: nil) let filledStar = UIImage(named: "filledStar", in: bundle, compatibleWith: self.traitCollection) let emptyStar = UIImage(named: "emptyStar", in: bundle, compatibleWith: self.traitCollection) let highlightedStar = UIImage(named: "highlightedStar", in: bundle, compatibleWith: self.traitCollection) for _ in 0..<starCount { // Create the button let button = UIButton() button.setImage(emptyStar, for: .normal) button.setImage(filledStar, for: .selected) button.setImage(highlightedStar, for: .highlighted) button.setImage(highlightedStar, for: [.highlighted, .selected]) // Add constraints button.translatesAutoresizingMaskIntoConstraints = false button.heightAnchor.constraint(equalToConstant: starSize.height).isActive = true button.widthAnchor.constraint(equalToConstant: starSize.width).isActive = true button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside) // Add the button to the stack addArrangedSubview(button) ratingButtons.append(button) }
}
private func updateButtonSelectionStates() {
for (index, button) in ratingButtons.enumerated() {
// If the index of a button is less than the rating, that button should be selected.
button.isSelected = index < rating
}
}
}
回答1件
あなたの回答
tips
プレビュー