UIButton 서브 클래스는 글꼴 변경에서 클릭

0

질문

나는 몇 가지 이상한 행동을 배열의 버튼이 나는 내장 된 스토리. 내가 있는 4 개 버튼의 각 사용자 지정 형식 TakesContainerButton 을 때 버튼을 클릭하면 그것을 변경하는 시스템의 글꼴이지만,때 다른 버튼을 클릭하면 이전에 버튼을 반환하고 원하는 글꼴을 확실하지 않 여기에 무슨 일이 일어나고 있는지에

이튼은 또한 임베디드 스택에서 보면,문제

여기에 구현할 때는 하나의 단추를 누르는 곳 buttons 배열의 버튼 4

@IBAction func filterPressed(_ sender: TakesContainerButton) {
        for button in buttons {
            button.unclick()
        }
        sender.click()
    }

여기에는 사용자 정의 클래스

class TakesContainerButton: UIButton {

        
        var bottom = UIView()
        
        func click(){
            self.setTitleColor(.darkGray, for: .normal)
            let xOffset:CGFloat = 10
            bottom = UIView(frame: CGRect(x: xOffset / 2, y: self.frame.height - 3, width: self.frame.width - xOffset, height: 3))
            bottom.layer.cornerRadius = 1.5
            bottom.backgroundColor = .darkGray
            self.addSubview(bottom)
        }
        
        func unclick(){
            bottom.removeFromSuperview()
            self.setTitleColor(UIColor(hex: "8B8B8B"), for: .normal)
        }
        
        override func awakeFromNib(){
            setFont()
        }
        
        func setFont(){
            self.titleLabel?.font = UIFont(name: "Lato-Bold", size: 12)
        }
    }
ios swift uibutton
2021-11-23 22:12:09
1

최고의 응답

0

은 어떤 특별한 이유는 당신을 호출하는 setFont()모든 클릭합니다. 으로 나가는 것을 볼 수 있는 변경되지 않는 글꼴을 설정해야 합니다 이 글꼴을 시기 적재 및 떠나는 글꼴입니다.

2021-11-23 22:56:54

원래 그것은 단지 awakeFromNib 지만,나는 그것을 경험하고 있는 문제점 그래서 제가 모두에서 클릭을 먼저 설치
tHatpart

당신이 필요하지 않 글꼴을 설정합니다.
Anubhav Giri

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................