Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsic committed Dec 17, 2021
1 parent 0a893df commit 275af73
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 204 deletions.
Binary file modified Pictures/SGPagingView.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


## 前言
* QQ群:825339547
* 2.0.0 版本起,升级为 Swift 编程语言
* [Objc 版本说明](https://github.com/kingsic/SGPagingView/blob/master/READMEOBJC.md)

Expand All @@ -14,20 +15,22 @@
![](https://github.com/kingsic/Kar98k/blob/master/SGPagingView/SGPagingView.gif)


## Installation
* CocoaPods 导入 pod 'SGPagingView', '~> 2.0.0'
## Installation
* CocoaPods 导入 pod 'SGPagingView', '~> 2.1.0'


## 代码介绍
* 初始化方法
```
// 配置类
let configure = SGPagingTitleViewConfigure()
// PagingTitle
// 标题视图
let pagingTitleView = SGPagingTitleView(frame: frame, titles: titles, configure: configure)
pagingTitleView.delegate = self
view.addSubview(pagingTitleView)
// PagingContent
// 内容视图
let pagingContentView = SGPagingContentScrollView(frame: frame, parentVC: self, childVCs: childVCs)
pagingContentView.delegate = self
view.addSubview(pagingContentView)
Expand All @@ -54,5 +57,5 @@ func pagingContentView(contentView: SGPagingContentView, progress: CGFloat, curr


## Concluding remarks
* 如有问题 [issues](https://github.com/kingsic/SGPagingView/issues) 或加QQ群:825339547
* 如有问题 [issues](https://github.com/kingsic/SGPagingView/issues)

29 changes: 8 additions & 21 deletions READMEOBJC.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

## 前言
* 从2.0.0版本起,Swift 语言将代替之前的 Objective-C 语言
* Objective-C 语言最后的版本号是:[1.7.2](https://github.com/kingsic/SGPagingView/releases/tag/1.7.2),且不在给予维护
* 从 2.0.0 版本起,升级为 Swift 编程语言
* 从 2.1.0 版本起,已兼容 Objective-C 语义
* Objective-C 编程语言最后的版本是 [1.7.2](https://github.com/kingsic/SGPagingView/releases/tag/1.7.2),且不在给予维护


## 结构图
```
Expand All @@ -23,13 +25,14 @@ SGPageContentCollectionView(内部由 UICollectionView 实现)
## 代码介绍
* 初始化方法
```
/// pageTitleViewConfigure
// 配置类
SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
/// pageTitleView
// 标题视图
SGPageTitleView *pageTitleView = [SGPageTitleView pageTitleViewWithFrame:frame delegate:self titleNames:titleNames configure:configure];
[self.view addSubview:pageTitleView];
/// pageContent
// 内容视图
SGPageContentScrollView *pageContentScrollView = [[SGPageContentScrollView alloc] initWithFrame:frame parentVC:self childVCs:childVCs];
pageContentScrollView.delegatePageContentScrollView = self;
[self.view addSubview:pageContentScrollView];
Expand Down Expand Up @@ -121,26 +124,10 @@ b. 实现 SGPageContentScrollView 的 pageContentScrollView:index:代理方法

* 2017-10-17 :v1.3.0 版本升级:新增 SGPageTitleViewConfigure 类及支持指示器遮盖样式

* 2018-05-08 :v1.3.7 修复 1.3.6 版本选中标题重复点击恢复默认状态及新增相关配置属性

* 2018-07-09 :v1.5.0 版本升级:具体相关信息请查看 [releases](https://github.com/kingsic/SGPagingView/releases) 中版本介绍

* 2018-08-28 :v1.5.2 SGPageContentScrollView 内部代码优化处理(感谢 [petyou](https://github.com/petyou) 提供的优化方案)

* 2018-09-01 :v1.5.3 新增 SGPagingViewPopGestureVC 用于解决侧滑返回手势

* 2018-09-26 :v1.5.5 标题文字缩放效果由文字缩放调整为控件缩放

* 2018-12-01 :v1.5.6 SGPageTitleView 新增重置标题、指示器颜色方法

* 2019-01-09 :v1.6.0 版本升级:支持 autolayout 布局

* 2019-03-27 :v1.6.1 修复 addBadgeForIndex 方法内 badge 布局问题

* 2019-07-17 :v1.6.3 修复设置图片样式下图片布局问题及内部代码优化处理

* 2019-07-20 :v1.6.5 滚动样式下 titleTextZoom 属性支持指示器下划线及遮盖样式的滚动

* 2019-07-22 :v1.6.6 SGPageTitleViewConfigure 新增 equivalence 属性支持静止样式下标题从左到右自动布局

* 2019-07-27 :v1.6.7 标题支持上下行及 titleGradientEffect 属性与 resetTitleColor:titleSelectedColor: 方法兼容
Expand Down
2 changes: 1 addition & 1 deletion SGPagingView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |spec|
spec.name = "SGPagingView"
spec.version = "2.0.0"
spec.version = "2.1.0"
spec.summary = "A powerful and easy to use segment view"
spec.homepage = "https://github.com/kingsic/SGPagingView"
spec.license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions SGPagingView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@
8D173CFE2763A90B00B59F4D /* PagingContent */ = {
isa = PBXGroup;
children = (
8D173CFF2763A90B00B59F4D /* SGPagingContentView.swift */,
8D173D012763A90B00B59F4D /* SGPagingContentViewDelegate.swift */,
8D173D022763A90B00B59F4D /* SGPagingContentCollectionView.swift */,
8D173D002763A90B00B59F4D /* SGPagingContentScrollView.swift */,
8D173CFF2763A90B00B59F4D /* SGPagingContentView.swift */,
8D173D012763A90B00B59F4D /* SGPagingContentViewDelegate.swift */,
);
path = PagingContent;
sourceTree = "<group>";
Expand All @@ -231,9 +231,9 @@
8D173D192763A92600B59F4D /* FixedTwoVC.swift */,
8D173D102763A92600B59F4D /* ScrollVC.swift */,
8D173D232763A92600B59F4D /* AttributedVC.swift */,
8D173D172763A92600B59F4D /* BadgeVC.swift */,
8D173D242763A92600B59F4D /* GradientEffectVC.swift */,
8D173D182763A92600B59F4D /* ZoomVC.swift */,
8D173D172763A92600B59F4D /* BadgeVC.swift */,
8D173D1B2763A92600B59F4D /* IFixedVC.swift */,
8D173D1A2763A92600B59F4D /* IDynamicVC.swift */,
8D173D162763A92600B59F4D /* CoverOneVC.swift */,
Expand Down
76 changes: 74 additions & 2 deletions SGPagingView/Example/AttributedVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class AttributedVC: UIViewController, SGPagingTitleViewDelegate {
class AttributedVC: UIViewController {

deinit {
print("AttributedVC - deinit")
Expand All @@ -21,6 +21,8 @@ class AttributedVC: UIViewController, SGPagingTitleViewDelegate {
view.backgroundColor = .green

HY()

addPagingView()
}

func HY() {
Expand Down Expand Up @@ -67,15 +69,85 @@ class AttributedVC: UIViewController, SGPagingTitleViewDelegate {
rightBtn.backgroundColor = .orange
rightBtn.setTitleColor(.white, for: .normal)
rightBtn.titleLabel!.lineBreakMode = .byWordWrapping
rightBtn.titleLabel?.textAlignment = .center
rightBtn.titleLabel!.font = UIFont.systemFont(ofSize: 12)
view.addSubview(rightBtn)

let rightBtnText = "订阅\n 520"
let rightBtnText = "订阅\n520"
let attriStr = NSMutableAttributedString(string: rightBtnText)
let dict = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17), NSAttributedString.Key.foregroundColor: UIColor.white]
let range = NSMakeRange(0, 2)
attriStr.addAttributes(dict, range: range)
rightBtn.setAttributedTitle(attriStr, for: .normal)
}


func addPagingView() {
view.addSubview(pagingTitleView)
view.addSubview(pagingContentView)
}

lazy var pagingTitleView: SGPagingTitleView = {
let configure = SGPagingTitleViewConfigure()
configure.indicatorLocation = .Top
configure.indicatorHeight = 5

let frame = CGRect.init(x: 0, y: 220, width: UIScreen.width, height: 44)
let titles = ["聊天", "主播", "排行", "贵宾"]
let pagingTitle = SGPagingTitleView(frame: frame, titles: titles, configure: configure)
pagingTitle.delegate = self

let text = "订阅\n520"
let attriStr = NSMutableAttributedString(string: text)
let dict = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17), NSAttributedString.Key.foregroundColor: UIColor.black]
let range = NSMakeRange(0, 2)
attriStr.addAttributes(dict, range: range)
let dict2 = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13), NSAttributedString.Key.foregroundColor: UIColor.black]
let range2 = NSMakeRange(text.count - 3, 3)
attriStr.addAttributes(dict2, range: range2)

let selectedAttriStr = NSMutableAttributedString(string: text)
let selectedDict = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17), NSAttributedString.Key.foregroundColor: UIColor.red]
let selectedRange = NSMakeRange(0, 2)
selectedAttriStr.addAttributes(selectedDict, range: selectedRange)
let selectedDict2 = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13), NSAttributedString.Key.foregroundColor: UIColor.red]
let selectedRange2 = NSMakeRange(text.count - 3, 3)
selectedAttriStr.addAttributes(selectedDict2, range: selectedRange2)

pagingTitle.setTitle(attributed: attriStr, selectedAttributed: selectedAttriStr, index: 3)

let imageUrl = "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"
pagingTitle.setBackgroundImage(name: imageUrl, selectedName: nil, index: 1)
return pagingTitle
}()

lazy var pagingContentView: SGPagingContentScrollView = {
let vc1 = UIViewController()
vc1.view.backgroundColor = .orange
let vc2 = UIViewController()
vc2.view.backgroundColor = .purple
let vc3 = UIViewController()
vc3.view.backgroundColor = .blue
let vc4 = UIViewController()
vc4.view.backgroundColor = .brown
let vcs = [vc1, vc2, vc3, vc4]

let y: CGFloat = pagingTitleView.frame.maxY + 20
let tempRect: CGRect = CGRect.init(x: 0, y: y, width: UIScreen.width, height: 200)
let pagingContent = SGPagingContentScrollView(frame: tempRect, parentVC: self, childVCs: vcs)
pagingContent.delegate = self
pagingContent.isAnimated = true
pagingContent.isBounces = true
return pagingContent
}()
}

extension AttributedVC: SGPagingTitleViewDelegate, SGPagingContentViewDelegate {
func pagingTitleView(titleView: SGPagingTitleView, index: Int) {
pagingContentView.setPagingContentView(index: index)
}

func pagingContentView(contentView: SGPagingContentView, progress: CGFloat, currentIndex: Int, targetIndex: Int) {
pagingTitleView.setPagingTitleView(progress: progress, currentIndex: currentIndex, targetIndex: targetIndex)
}
}
2 changes: 1 addition & 1 deletion SGPagingView/Example/FixedOneVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FixedOneVC: UIViewController, SGPagingTitleViewDelegate, SGPagingContentVi

let frame = CGRect.init(x: 0, y: UIScreen.navBarHeight, width: UIScreen
.width, height: 44)
let titles = ["关注", "推荐", "热榜", "免费小说"]
let titles = ["滚动", "内容视图", "最左或最右", "回弹"]
let pagingTitle = SGPagingTitleView(frame: frame, titles: titles, configure: configure)
pagingTitle.delegate = self
view.addSubview(pagingTitle)
Expand Down
2 changes: 1 addition & 1 deletion SGPagingView/Example/FixedTwoVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FixedTwoVC: UIViewController, SGPagingTitleViewDelegate, SGPagingContentVi
let configure = SGPagingTitleViewConfigure()

let frame = CGRect.init(x: 0, y: UIScreen.navBarHeight, width: UIScreen.width, height: 44)
let titles = ["关注", "推荐", "热榜", "免费小说"]
let titles = ["点击", "标题", "内容", "动画切换"]
let pagingTitle = SGPagingTitleView(frame: frame, titles: titles, configure: configure)
pagingTitle.delegate = self
return pagingTitle
Expand Down
62 changes: 20 additions & 42 deletions SGPagingView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@ import UIKit

class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var dataSource = ["固定样式一(回弹效果)", "固定样式二(动画效果)", "滚动样式(指定下标值)", "富文本样式", "badge 样式", "文字渐变效果", "文字缩放效果", "指示器固定样式(爱奇艺效果)", "指示器动态样式", "指示器遮盖样式", "百度网盘传输界面样式", "悬浮效果", "悬浮效果Pro"]

var dataSource = [
["固定样式一(回弹效果)": FixedOneVC.self],
["固定样式二(动画效果)": FixedTwoVC.self],
["滚动样式(指定下标值)": ScrollVC.self],
["富文本样式": AttributedVC.self],
["文字渐变效果": GradientEffectVC.self],
["文字缩放效果": ZoomVC.self],
["通知消息样式": BadgeVC.self],
["指示器固定样式(爱奇艺首页效果)": IFixedVC.self],
["指示器动态样式": IDynamicVC.self],
["指示器遮盖样式": CoverOneVC.self],
["百度网盘传输界面样式": CoverTwoVC.self],
["悬浮效果": SuspensionVC.self],
["悬浮效果Pro": SuspensionProVC.self]
]

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -19,7 +34,6 @@ class ViewController: UIViewController {
tableView.tableFooterView = UIView()
}


}

extension ViewController: UITableViewDataSource {
Expand All @@ -31,52 +45,16 @@ extension ViewController: UITableViewDataSource {
cell.accessoryType = .disclosureIndicator
cell.backgroundColor = .clear
cell.selectionStyle = .none
cell.textLabel?.text = dataSource[indexPath.row];
cell.textLabel?.text = dataSource[indexPath.row].keys.first
return cell
}
}

extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
let vc = FixedOneVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 1 {
let vc = FixedTwoVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 2 {
let vc = ScrollVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 3 {
let vc = AttributedVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 4 {
let vc = BadgeVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 5 {
let vc = GradientEffectVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 6 {
let vc = ZoomVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 7 {
let vc = IFixedVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 8 {
let vc = IDynamicVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 9 {
let vc = CoverOneVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 10 {
let vc = CoverTwoVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 11 {
let vc = SuspensionVC()
navigationController?.pushViewController(vc, animated: true)
} else if indexPath.row == 12 {
let vc = SuspensionProVC()
navigationController?.pushViewController(vc, animated: true)
let vc = dataSource[indexPath.row].values.first
if let tempVC = vc {
navigationController?.pushViewController(tempVC.init(), animated: true)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Extensions/UIButton+SGPagingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

public enum ImageLocation {
@objc public enum ImageLocation: Int {
case left, right, top, bottom
}

Expand All @@ -20,7 +20,7 @@ public extension UIButton {
/// - parameter location: location of image relative to title
/// - parameter space: space between image and title
/// - parameter completion: set image and title
func setImage(location: ImageLocation, space: CGFloat, completion: (UIButton) -> ()) {
@objc func setImage(location: ImageLocation, space: CGFloat, completion: (UIButton) -> ()) {
completion(self)
setImage(location: location, space: space)
}
Expand All @@ -31,7 +31,7 @@ public extension UIButton {
///
/// - parameter location: Location of image relative to title
/// - parameter space: Space between image and title
func setImage(location: ImageLocation, space: CGFloat) {
@objc func setImage(location: ImageLocation, space: CGFloat) {

let imageView_Width = imageView?.frame.size.width
let imageView_Height = imageView?.frame.size.height
Expand Down
Loading

0 comments on commit 275af73

Please sign in to comment.