Skip to content

Commit

Permalink
del osx code
Browse files Browse the repository at this point in the history
  • Loading branch information
ccworld1000 committed Mar 2, 2018
1 parent 5fced8b commit 70b3b3d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 114 deletions.
21 changes: 9 additions & 12 deletions OKKLineMin/OKKLineSwift/Views/OKKLineDrawView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,16 @@ class OKKLineDrawView: OKView {

okBackgroundColor = configuration.main.backgroundColor

#if os(iOS) || os(tvOS)
// 捏合手势
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinchAction(_:)))
addGestureRecognizer(pinchGesture)
// 长按手势
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:)))
addGestureRecognizer(longPressGesture)
// 移动手势
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGestureAction(_:)))
addGestureRecognizer(panGesture)

// 捏合手势
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinchAction(_:)))
addGestureRecognizer(pinchGesture)
// 长按手势
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:)))
addGestureRecognizer(longPressGesture)
// 移动手势
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGestureAction(_:)))
addGestureRecognizer(panGesture)
#endif

loadingSubviews()

}
Expand Down
146 changes: 44 additions & 102 deletions OKKLineMin/OKKLineSwift/Views/SegmentView/OKSegmentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,110 +69,52 @@ class OKSegmentView: OKView {
make.edges.equalToSuperview()
}

#if os(iOS) || os(tvOS)

var lastBtn: OKButton?
for (index, title) in titles.enumerated() {
let btn = OKButton(type: .custom)
btn.tag = index
btn.setTitle(title, for: .normal)
btn.setTitleColor(OKColor.white, for: .normal)
btn.titleLabel?.font = OKFont.systemFont(size: 12)
btn.addTarget(self, action: #selector(selectedAction(_:)), for: .touchUpInside)
scrollView.addSubview(btn)

switch direction {
case .horizontal:

btn.snp.makeConstraints({ (make) in
make.top.bottom.equalToSuperview()
make.size.equalTo(CGSize(width: 60, height: 44))
// 处理第一个button
if let lastBtn = lastBtn {
make.leading.equalTo(lastBtn.snp.trailing)
} else {
make.leading.equalToSuperview()
}
// 处理最后一个btn
if index == titles.count - 1 {
make.trailing.equalToSuperview()
}
})

case .vertical:
btn.snp.makeConstraints({ (make) in
make.leading.trailing.equalToSuperview()
make.size.equalTo(CGSize(width: 50, height: 44))
// 处理第一个button
if let lastBtn = lastBtn {
make.top.equalTo(lastBtn.snp.bottom)
} else {
make.top.equalToSuperview()
}
// 处理最后一个btn
if index == titles.count - 1 {
make.bottom.equalToSuperview()
}
})
}
lastBtn = btn
}

#else
var lastBtn: OKButton?
for (index, title) in titles.enumerated() {
let btn = OKButton(type: .custom)
btn.tag = index
btn.setTitle(title, for: .normal)
btn.setTitleColor(OKColor.white, for: .normal)
btn.titleLabel?.font = OKFont.systemFont(size: 12)
btn.addTarget(self, action: #selector(selectedAction(_:)), for: .touchUpInside)
scrollView.addSubview(btn)

let containerView = OKView()

var lastBtn: OKButton?
for (index, title) in titles.enumerated() {

let btn = OKButton()
btn.tag = index
btn.setButtonType(.pushOnPushOff)
btn.bezelStyle = .rounded
btn.target = self
btn.action = #selector(selectedAction(_:))
btn.okBackgroundColor = configuration.main.backgroundColor
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
let attr: [NSAttributedStringKey : Any]? = [NSAttributedStringKey.font : OKFont.systemFont(size: 12),
NSAttributedStringKey.foregroundColor : OKColor.white,
NSAttributedStringKey.paragraphStyle : paragraph]
btn.attributedTitle = NSAttributedString(string: title, attributes: attr)

containerView.addSubview(btn)

switch direction {

case .horizontal:
btn.snp.makeConstraints({ (make) in
make.top.bottom.equalToSuperview()
make.width.equalTo(100)
if let lastBtn = lastBtn {
make.leading.equalTo(lastBtn.snp.trailing)
} else {
make.leading.equalToSuperview()
}
})

case .vertical:

btn.snp.makeConstraints({ (make) in
make.leading.trailing.equalToSuperview()
make.height.equalTo(44.0)
if let lastBtn = lastBtn {
make.top.equalTo(lastBtn.snp.bottom)
} else {
make.top.equalToSuperview()
}
})
}
lastBtn = btn
switch direction {
case .horizontal:

btn.snp.makeConstraints({ (make) in
make.top.bottom.equalToSuperview()
make.size.equalTo(CGSize(width: 60, height: 44))
// 处理第一个button
if let lastBtn = lastBtn {
make.leading.equalTo(lastBtn.snp.trailing)
} else {
make.leading.equalToSuperview()
}
// 处理最后一个btn
if index == titles.count - 1 {
make.trailing.equalToSuperview()
}
})

case .vertical:
btn.snp.makeConstraints({ (make) in
make.leading.trailing.equalToSuperview()
make.size.equalTo(CGSize(width: 50, height: 44))
// 处理第一个button
if let lastBtn = lastBtn {
make.top.equalTo(lastBtn.snp.bottom)
} else {
make.top.equalToSuperview()
}
// 处理最后一个btn
if index == titles.count - 1 {
make.bottom.equalToSuperview()
}
})
}

scrollView.documentView = containerView

#endif

lastBtn = btn
}
}

required init?(coder aDecoder: NSCoder) {
Expand Down

0 comments on commit 70b3b3d

Please sign in to comment.