카테고리 없음

swift ColletionView cell 크기 오류 해결해보자

kingarthur 2024. 7. 5. 20:11

오늘 이것 때문에 시간을 얼마나 버렸는지....

    func setupView() {
//        backgroundColor = .red
        //cell은 contentView 사용해야함
        self.contentView.addSubview(self.menuTitleLabel)
        self.contentView.addSubview(self.menuImage)
        self.contentView.addSubview(self.priceLabel)
        
        NSLayoutConstraint.activate([
            menuImage.topAnchor.constraint(equalTo: contentView.topAnchor),
            menuImage.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
            menuImage.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
            menuImage.heightAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: 0.7),
//            menuImage.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
        ])

높이를 주니 해결이 되었다....

진짜 아무것도 아니였지만 오만시도 다 해봤다. 

그래도 해결해도 행복하다. 

 

    func setupView() {
//        backgroundColor = .red
        //cell은 contentView 사용해야함
        self.contentView.addSubview(self.menuTitleLabel)
        self.contentView.addSubview(self.menuImage)
        self.contentView.addSubview(self.priceLabel)
        
        NSLayoutConstraint.activate([
            menuImage.topAnchor.constraint(equalTo: contentView.topAnchor),
            menuImage.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
            menuImage.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
//            menuImage.heightAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: 0.7),
            menuImage.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
        ])

위에처럼 버텀을 넣어버리면 이상하게 나온다 셀이...

근데 둘다 적용하면 에러난다. 

 

그래도 문제는 해결해서 너무 좋다. 이제 다음 단계로 가보자.