Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 마이페이지 화면 - ECH-46 #13

Merged
merged 7 commits into from
Jan 10, 2025
Merged

Conversation

mint3382
Copy link
Member

화면

마이페이지 화면 내 투표리스트 화면
diary_scroll diary_scroll

트러블 슈팅

Segment Control Custom

Segment Control을 선택시 밑에 선을 그려주는 모양으로 custom

class UnderlineSegmentedControl: UISegmentedControl {
    private lazy var underlineBackView: UIView = {
        let width = self.bounds.width
        let height = 2.0
        let xPosition = CGFloat(self.selectedSegmentIndex * Int(width))
        let yPosition = self.bounds.size.height - 1.0
        let frame = CGRect(x: xPosition, y: yPosition, width: width, height: height)
        let view = UIView(frame: frame)
        
        view.backgroundColor = .grayscale40Disabled
        self.addSubview(view)
        
        return view
    }()
    
    private lazy var underlineView: UIView = {
        let width = self.bounds.width / CGFloat(self.numberOfSegments)
        let height = 2.0
        let xPosition = CGFloat(self.selectedSegmentIndex * Int(width))
        let yPosition = self.bounds.size.height - 1.0
        let frame = CGRect(x: xPosition, y: yPosition, width: width, height: height)
        let view = UIView(frame: frame)
        
        view.backgroundColor = .black
        self.addSubview(view)
        
        return view
    }()
    
    override init(items: [Any]?) {
        super.init(items: items)
        
        self.removeDivider()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let underlineFinalXPosition = (self.bounds.width / CGFloat(self.numberOfSegments)) * CGFloat(self.selectedSegmentIndex)
        
        UIView.animate(withDuration: 0.1) {
            self.underlineView.frame.origin.x = underlineFinalXPosition
        }
    }
    
    private func removeDivider() {
        let image = UIImage()
        
        self.setBackgroundImage(image, for: .normal, barMetrics: .default)
        self.setBackgroundImage(image, for: .selected, barMetrics: .default)
        self.setBackgroundImage(image, for: .highlighted, barMetrics: .default)
        
        self.setDividerImage(image, forLeftSegmentState: .selected, rightSegmentState: .normal, barMetrics: .default)
    }
}

@mint3382 mint3382 added the ✨ Feature 기능 개발 label Jan 10, 2025
@mint3382 mint3382 self-assigned this Jan 10, 2025
Copy link

@mint3382 mint3382 merged commit 4f293fb into develop Jan 10, 2025
@mint3382 mint3382 deleted the Feature/MyPageView branch January 10, 2025 07:25
@mint3382 mint3382 linked an issue Jan 10, 2025 that may be closed by this pull request
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] 마이페이지 화면 구현
1 participant