Skip to content

Commit

Permalink
Allow to create empty segments
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Aug 6, 2019
1 parent 2cc9b3d commit 2945414
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
8 changes: 2 additions & 6 deletions MXSegmentedControl/MXSegment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ public class MXSegment: UIButton {
/// The segment width
public var width: CGFloat {
get {
if _width == UIView.noIntrinsicMetric {
return intrinsicContentSize.width
}
return _width
guard _width == UIView.noIntrinsicMetric else { return _width }
return intrinsicContentSize.width
}
set { _width = newValue }
}
Expand Down Expand Up @@ -257,7 +255,6 @@ extension MXSegment {
let titleSize = titleLabel.intrinsicContentSize

// Compute Title Label Frame

var width = contentRect.width
width -= titleEdgeInsets.left
width -= titleEdgeInsets.right
Expand Down Expand Up @@ -394,7 +391,6 @@ extension MXSegment {

imageView.frame = CGRect(x: x, y: y, width: width, height: height)
//

}

}
12 changes: 5 additions & 7 deletions MXSegmentedControl/MXSegmentedControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ import UIKit
}

deinit {
if let scrollView = scrollView {
scrollView.removeObserver(self, forKeyPath: keyPath, context: &context)
}
guard let scrollView = scrollView else { return }
scrollView.removeObserver(self, forKeyPath: keyPath, context: &context)
}

// MARK: Layout
Expand All @@ -194,8 +193,7 @@ import UIKit
open override func layoutSubviews() {
super.layoutSubviews()

var frame = self.bounds //container.inset(by: margin)//CGRect.insetBy(self.bounds)
//UIEdgeInsetsInsetRect(bounds, contentEdgeInsets)
var frame = self.bounds.inset(by: contentEdgeInsets)
_scrollView.frame = frame

let size = contentView.intrinsicContentSize
Expand Down Expand Up @@ -386,7 +384,7 @@ extension MXSegmentedControl {
return contentView.segments.count
}

private func newSegment() -> MXSegment {
public func newSegment() -> MXSegment {

let segment = MXSegment()

Expand Down Expand Up @@ -482,7 +480,7 @@ extension MXSegmentedControl {

class ContentView: UIView {

internal(set) var segments = [MXSegment]()
var segments = [MXSegment]()

var separators = Separators()

Expand Down

0 comments on commit 2945414

Please sign in to comment.