bài viết trước , chúng ta đã có cái nhìn tổng quan cũng như các thao tác căn bản về CocoaPods. Ở bài viết này, mình xin giới thiệu một vài các dependency hữu ích để sử dụng khi phát triển một ứng dụng iOS.

I. SDCAlertView

1) Tính năng

  • Hiển thị các thông báo với nội dung có thể custom tùy ý theo mục đích cá nhân.
  • Alert được hiển thị giống với UIAlertView nhưng nội dung bên trong có thể custom.
  • Được viết trên ngôn ngữ Swift, nhưng có thể sử dụng cho cả Objective-C và Swift.
    alt

2) Sử Dụng

Yêu cầu
  • Swift 3
  • iOS 8 hoặc cao hơn.
Cài đặt với CocoaPods
  • Thêm Dependency vào file Podfile
platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
  pod 'SDCAlertView', '~> 7.1'
end
  • Chạy lệnh pod install
Sử dụng cơ bản
let alert = AlertController(title: "Title", message: "This is a message", preferredStyle: .Alert)
alert.add(AlertAction(title: "Cancel", style: .default))
alert.add(AlertAction(title: "OK", style: .preferred))
alert.present()

// or use the convenience methods:

AlertController.alert(withTitle: "Title", message: "This is a message", actionTitle: "OK")
AlertController.sheet(withTitle: "Action sheet title", "Action sheet message", actions: ["OK", "Cancel"])
Custom Content View
  • Chúng ta có thể thêm 1 Subview vào Alert. Subview có thể là bất cứ thứ gì chúng ta mong muốn.
  • Ví dụ dưới đây, chúng ta thêm 1 icon loading vào alert:
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.translatesAutoresizingMaskIntoConstraints = false
spinner.startAnimating()

let alert = AlertController(title: "Title", message: "Please wait...")
alert.contentView.addSubview(spinner)

spinner.centerXAnchor.constraintEqualToAnchor(alert.contentView.centerXAnchor).active = true
spinner.topAnchor.constraintEqualToAnchor(alert.contentView.topAnchor).active = true
spinner.bottomAnchor.constraintEqualToAnchor(alert.contentView.bottomAnchor).active = true

alert.present()

3) Tham khảo

SDCAlertView

II. ReachabilitySwift

1) Tính Năng

  • Là một Dependency thay thế cho class Reachability mặc định của Apple (Class này hỗ trợ việc kiểm tra kết nối Wifi, Bluetooth của thiết bị).
  • Được viết theo ngôn ngữ Swift, hỗ trợ Swift 2.2 và Swift 3

2) Sử Dụng

Cài đặt với CocoaPods
  • Thêm dependency vào file Podfile
pod 'ReachabilitySwift'
  • Chạy lệnh pod install
  • Import vào file code import ReachabilitySwift
Sử Dụng Căn Bản
  • Dùng như 1 class bình thường.

3) Tham Khảo

ReachabilitySwift

III. RappleProgressHUD

1) Tính Năng

  • Giúp hiển thị "Loading Process" một cách nhanh chóng và tiện lợi.
  • Hỗ trợ custom nội dung, màu sắc, font chữ,... cho biểu tượng "Loading".
    alt

2) Sử Dụng

Cài đặt với CocoaPods
  • Thêm dependency vào file Podfile
pod "RappleProgressHUD" 
  • Chạy lệnh pod install
  • Import vào file code import RappleProgressHUD
Sử dụng cơ bản
  • Hiển thị
RappleActivityIndicatorView.startAnimating()
  • Ngưng hiển thị
RappleActivityIndicatorView.stopAnimating()

3)Tham Khảo

RappleProgressHUD

IV. SwiftyMarkdown

1) Tính năng

  • Hỗ trợ convert file Markdown và string về định dạng NSAttributedString trong Swift.
  • Có thể tùy chỉnh font chữ và màu sắc của từng thành phần theo sở thích.

2) Sử Dụng

Cài đặt với CocoaPods
  • Thêm dependency vào file Podfile
pod "SwiftyMarkdown" 
  • Chạy lệnh pod install
  • Import vào file code import SwiftyMarkdown
Sử dụng cơ bản
  • Text String
let md = SwiftyMarkdown(string: "# Heading\nMy *Markdown* string")
md.attributedString()
  • Custom lại định dạng text
md.body.fontName = "AvenirNextCondensed-Medium"

md.h1.color = UIColor.redColor()
md.h1.fontName = "AvenirNextCondensed-Bold"
Định Dạng Hỗ Trợ
  • Hiện tại thì SwiftyMarkdown hỗ trợ khá đầy đủ các định dạng của Markdown như Heading, chữ Italic và Bold, Link. Tuy nhiên, một vài định dạng khác như List vẫn chưa được hỗ trợ.
  • Danh sách các định dạng đã hỗ trợ:
*italics* or _italics_
**bold** or __bold__

# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6

`code`
[Links](http://voyagetravelapps.com/)

3) Tham Khảo

SwiftyMarkdown