Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
fix horizontal and vertical autolayout
Browse files Browse the repository at this point in the history
  • Loading branch information
VeinGuo committed Sep 6, 2017
1 parent 182add8 commit ab9257f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions VGSegment/VGSegment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ open class VGSegment: UIView{
fatalError("init(coder:) has not been implemented")
}

open override func layoutSubviews() {
super.layoutSubviews()
scrollView.frame = bounds
let selectLabel = titleLabels[selectIndex]
let offsetX = min(max(0, selectLabel.center.x - bounds.width / 2),
max(0, scrollView.contentSize.width - bounds.width))
scrollView.setContentOffset(CGPoint(x:offsetX, y: 0), animated: false)
}

}

//MARK: - public
Expand Down

0 comments on commit ab9257f

Please sign in to comment.