View How to open link on Safari
guard let url = URL(string: "link") else { return } | |
UIApplication.shared.open(url) |
View How to create UIAlertController
// Создание контроллера | |
let aC = UIAlertController(title: "Название", message: "Описание", preferredStyle: .alert) | |
// Создание кнопки и действия для контроллера | |
let aA = UIAlertAction(title: "Закрыть", style: .default) { (action: UIAlertAction) in | |
print("Default") | |
} | |
// Добавление к контроллеру действия | |
aC.addAction(aA) | |
// Показать контроллер | |
present(aC, animated: true) |
View How to hide separator in TableView
// В viewDidLoad | |
self.tableView.separatorColor = UIColor.clear | |
// или | |
tableView.separatorStyle = .none |
View How to create Segue using Storyboard ID
let storyBoard: UIStoryboard = UIStoryboard(name: "Main VC", bundle: nil) | |
let newViewController = storyBoard.instantiateViewController(withIdentifier: "Your Storyboard ID") as! newViewController | |
self.present(newViewController, animated: true, completion: nil) |
View How to rotate UILabel
// 190 | |
yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) | |
// 180 | |
yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi) | |
// -90 | |
yourLabelName.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2) |
View How to create video background
import UIKit | |
import AVKit | |
import AVFoundation | |
class ViewController: UIViewController { | |
// Создаем плеер и инициализируем фоновое видео и укажем путь к нему | |
var player: AVPlayer? | |
let videoURL: NSURL = Bundle.main.url(forResource: "Название видео", withExtension: "Формат")! as NSURL |
View How to hide empty cells
// В viewDidLoad | |
tableView.tableFooterView = UIView(frame: CGRect.zero) |
View How to set cell height
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | |
return 50.0; | |
} |
OlderNewer