MRArticleViewController 版本 1.0.7

MRArticleViewController 1.0.7

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布时间最新发布2017年2月
SwiftSwift 版本3.0
SPM支持 SPM

Matthew Rigdon 维护。




  • Matthew Rigdon

MRArticleViewController

该框架允许您轻松设置 View Controller 以显示受 Apple 新闻应用启发的新闻文章。只需设置所需的字段并运行,您将为文章获得一个好的视图。

Preview Preview Preview

示例

要运行示例项目,克隆 repo,并首先从 Example 目录运行 pod install

要求

  • Swift 3:使用当前版本
  • Swift 2:使用 v0.2.0

安装

MRArticleViewController 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中

pod 'MRArticleViewController'

用法

  1. 导入模块

    import MRArticleViewController
  2. 继承 ArticleViewController

    class ViewController: ArticleViewController
  3. viewDidLoad 中,设置以下 必需 属性 super.viewDidLoad() 之前

    override func viewDidLoad() {
        // required
        imageView.image = UIImage(named: "pulpfiction")!
        headline = "LA gangsters witness supposed \"Divine Intervention\""
        author = "Quentin Tarantino"
        date = NSDate()
        body = bodyText
    
        super.viewDidLoad()
    }
  4. 可选:在 viewDidLoad 中,设置以下 可选 属性 super.viewDidLoad() 之前

    ...
    
    // Uses the algorithm from UIImageColors to extract the colors from the image and color the
    // background, headline, author, date, and body accordingly. Defaults to false, but highly
    // recommended to set to true. More on this feature below.
    autoColored = true
    
    // If you don't like the autoColor feature, you can also color each component individually
    backgroundColor = UIColor.black
    headlineColor = UIColor.yellow
    authorColor = UIColor.orange
    dateColor = UIColor.gray
    bodyColor = UIColor.gray
    
    super.viewDidLoad()

完成!🍻

关于 autoColored 的更多信息

此库利用了 UIImageColors 的算法。设置 autoColor = trueimage 中提取颜色并将背景颜色应用于背景

  • 主颜色应用于头条
  • 详情颜色应用于日期和正文
  • 次级颜色应用于作者
  • 注意,UIImageColors 不是依赖项,代码只是被移植到这个库中。

待办事项

想要你未见过的功能?提交一个问题,我会把它添加到待办事项列表中,或者自行修改并提交一个拉取请求。

[ ] 添加新样式

  • [ ] Swift 包管理器
  • [ ] Swift 包管理器

作者

Matthew Rigdon,

授权

MRArticleViewController遵循MIT许可。有关更多信息,请参阅LICENSE文件。请同时参考Panic的原始授权以了解autoColor功能。