Created
March 29, 2016 10:16
-
-
Save petrpavlik/0c5feaada5913cafde8a to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// ViewController.swift | |
// Alert | |
// | |
// Created by Petr Pavlik on 25/03/16. | |
// Copyright © 2016 Petr Pavlik. All rights reserved. | |
// | |
import UIKit | |
class AlertController: UIAlertController { | |
override func viewDidLayoutSubviews() { | |
super.viewDidLayoutSubviews() | |
if let topView = findTopViewInView(view), let bottomView = findBottomViewInView(view) { | |
view.tintColor = .whiteColor() | |
colorLabelsInView(topView, toColor: .greenColor()) | |
bottomView.backgroundColor = UIColor(red:0.910, green:0.286, blue:0.173, alpha: 1) | |
} | |
} | |
private func findTopViewInView(view: UIView) -> UIView? { | |
if let scrollView = view as? UIScrollView where scrollView.frame.origin.y == 0 { | |
return scrollView | |
} else if view.subviews.count > 0 { | |
for subview in view.subviews { | |
if let scrollView = findTopViewInView(subview) { | |
return scrollView | |
} | |
} | |
} | |
return nil | |
} | |
private func findBottomViewInView(view: UIView) -> UIView? { | |
if let scrollView = view as? UIScrollView where scrollView.frame.origin.y > 0 { | |
return scrollView | |
} else if view.subviews.count > 0 { | |
for subview in view.subviews { | |
if let scrollView = findBottomViewInView(subview) { | |
return scrollView | |
} | |
} | |
} | |
return nil | |
} | |
private func colorLabelsInView(view: UIView, toColor: UIColor) { | |
if let label = view as? UILabel { | |
label.textColor = toColor | |
} | |
for subview in view.subviews { | |
colorLabelsInView(subview, toColor: toColor) | |
} | |
} | |
} | |
class ViewController: UIViewController { | |
override func viewDidAppear(animated: Bool) { | |
super.viewDidAppear(animated) | |
let alert = AlertController(title: "Title", message: "Message", preferredStyle: .Alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil)) | |
presentViewController(alert, animated: true, completion: nil) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment