protocol SwitchViewControllerProtocol: UIViewController {
var childViewController: UIViewController? {get set}
}
extension SwitchViewControllerProtocol {
func switchChildViewController(_ viewController: UIViewController) {
childViewController = viewController
WebViewでhttpsのサイトにアクセスした際に証明書チェックがエラーになっても無理やり表示する
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
}
忘れられがちなSFSafariViewControllerについて
// サンプルコード
import SafariServices
func displayWebPage(url: String) {
if let url = URL(string: url) {
let vc = SFSafariViewController(url: url)
vc.modalPresentationStyle = .fullScreen
// UIScrollView全体のスナップショット
// https://gist.github.com/thestoics/1204051
extension UIScrollView {
public var snapshot: UIImage? {
UIGraphicsBeginImageContextWithOptions(contentSize, false, 0)
defer {
UIGraphicsEndImageContext()
}
guard let context = UIGraphicsGetCurrentContext() else { return nil }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import HealthKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard HKHealthStore.isHealthDataAvailable() else { | |
return | |
} |
- UIColorをカラーコードで生成する https://qiita.com/Kyome/items/eae6216b13c651254f64
import UIKit
extension UIColor {
convenience init(hex: String, alpha: CGFloat) {
let v = Int("000000" + hex, radix: 16) ?? 0
let r = CGFloat(v / Int(powf(256, 2)) % 256) / 255
// 下寄せ
valueField.contentVerticalAlignment = .bottom
let stringAttributes1: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.black,
.font: UIFont.systemFont(ofSize: 30.0)
]
let string1 = NSAttributedString(string: v, attributes: stringAttributes1)