Skip to content

Instantly share code, notes, and snippets.

@maxxfrazer
Created December 17, 2020 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxxfrazer/d1168facd3b303a4e648c6a24b844d74 to your computer and use it in GitHub Desktop.
Save maxxfrazer/d1168facd3b303a4e648c6a24b844d74 to your computer and use it in GitHub Desktop.
Initial UIViewController for Agora Broadcasting Blog
import UIKit
import AgoraRtcKit
class ViewController: UIViewController {
var joinButton: UIButton?
override func viewDidLoad() {
super.viewDidLoad()
addJoinButton()
}
@objc func showChannelView() {
self.present(ChannelViewController(), animated: true)
}
/// Adds a button which says "Join" to the view
/// This button takes you to the `ChannelViewController`
func addJoinButton() {
if self.joinButton != nil {
return
}
let button = UIButton(type: .custom)
button.setTitle("Join", for: .normal)
button.setTitleColor(.label, for: .normal)
button.setTitleColor(.secondaryLabel, for: .focused)
button.backgroundColor = .systemGray
button.addTarget(self, action: #selector(showChannelView), for: .touchUpInside)
self.view.addSubview(button)
button.frame = CGRect(
origin: CGPoint(x: self.view.bounds.width / 2 - 75, y: self.view.bounds.height / 2 - 25),
size: CGSize(width: 150, height: 50)
)
button.autoresizingMask = [
.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin
]
button.backgroundColor = .systemGreen
button.layer.cornerRadius = 25
self.joinButton = button
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment