Skip to content

Commit 6b6a339

Browse files
committed
Merge pull request #11 from bcylin/support-landscape
Support Landscape
2 parents 94fd256 + f309643 commit 6b6a339

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

EZLoadingActivity.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public struct EZLoadingActivity {
103103
convenience init(text: String, disableUI: Bool) {
104104
let width = UIScreen.ScreenWidth / Settings.WidthDivision
105105
let height = width / 3
106-
self.init(frame: CGRect(x: UIScreen.ScreenWidth/2 - width/2, y: UIScreen.ScreenHeight/2 - height/2, width: width, height: height))
106+
self.init(frame: CGRect(x: 0, y: 0, width: width, height: height))
107+
center = CGPoint(x: UIScreen.mainScreen().bounds.midX, y: UIScreen.mainScreen().bounds.midY)
108+
autoresizingMask = [.FlexibleTopMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleRightMargin]
107109
backgroundColor = Settings.BackgroundColor
108110
alpha = 1
109111
layer.cornerRadius = 8

EZLoadingActivity/ViewController.swift

+19-11
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,30 @@ import UIKit
1010

1111
class ViewController: UIViewController {
1212

13+
private lazy var button: UIButton = {
14+
let _button = UIButton(type: .System)
15+
_button.setTitle("Show EZLoadingActivity", forState: .Normal)
16+
_button.addTarget(self, action: Selector("showLoadingActivity:"), forControlEvents: .TouchUpInside)
17+
return _button
18+
}()
19+
1320
override func viewDidLoad() {
1421
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
16-
22+
view.addSubview(button)
23+
24+
if #available(iOS 9.0, *) {
25+
button.translatesAutoresizingMaskIntoConstraints = false
26+
button.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor).active = true
27+
button.centerYAnchor.constraintEqualToAnchor(view.centerYAnchor).active = true
28+
} else {
29+
button.sizeToFit()
30+
button.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
31+
button.autoresizingMask = [.FlexibleTopMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleRightMargin]
32+
}
1733
}
1834

19-
override func viewDidAppear(animated: Bool) {
20-
super.viewDidAppear(animated)
35+
@IBAction func showLoadingActivity(sender: UIButton) {
2136
EZLoadingActivity.showWithDelay("Testing..", disableUI: false, seconds: 3)
22-
23-
}
24-
override func didReceiveMemoryWarning() {
25-
super.didReceiveMemoryWarning()
26-
// Dispose of any resources that can be recreated.
2737
}
2838

29-
3039
}
31-

0 commit comments

Comments
 (0)