Created
August 15, 2018 14:40
-
-
Save DonMag/e4c09b18ca609aea4e6402ccc2f0b1a8 to your computer and use it in GitHub Desktop.
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
// | |
// AppDelegate.swift | |
// | |
// Created by Don Mag on 8/15/18. | |
// | |
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
window = UIWindow(frame: UIScreen.main.bounds) | |
let testHViewController = TestHViewController() | |
testHViewController.view.backgroundColor = UIColor.red | |
window!.rootViewController = testHViewController | |
window!.makeKeyAndVisible() | |
return true | |
} | |
} |
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
// | |
// TestHViewController.swift | |
// | |
// Created by Don Mag on 8/15/18. | |
// | |
import UIKit | |
@objc class CommonHeaderView: UIView { | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
// | |
resetViewHeight() | |
print("resetViewHeight is :\(self.frame.height)") | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
resetViewHeight() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
} | |
//MARK:- Reset Height as per device size | |
func resetViewHeight() | |
{ | |
self.heightAnchor.constraint(equalTo: self.widthAnchor, multiplier: CGFloat(115.0/320.0), constant: 0).isActive = true | |
} | |
} | |
class TestHViewController: UIViewController { | |
let hView: CommonHeaderView = { | |
let v = CommonHeaderView() | |
v.translatesAutoresizingMaskIntoConstraints = false | |
v.backgroundColor = .blue | |
return v | |
}() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.addSubview(hView) | |
NSLayoutConstraint.activate([ | |
hView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0), | |
hView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0), | |
hView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0), | |
]) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment