Skip to content

Commit

Permalink
Merge pull request #27 from jinSasaki/refactor-and-support-iphonex
Browse files Browse the repository at this point in the history
Refactor and support iPhoneX
  • Loading branch information
jinSasaki committed Dec 8, 2017
2 parents b0bbe83 + 7c8ef5d commit 5fb5b94
Show file tree
Hide file tree
Showing 13 changed files with 463 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
4.0.2
2 changes: 1 addition & 1 deletion AlertBar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AlertBar"
s.version = "0.3.3"
s.version = "0.4.0"
s.summary = "An easy alert on status bar."
s.homepage = "https://github.com/jinSasaki/AlertBar"
s.screenshots = "https://github.com/jinSasaki/AlertBar/raw/master/assets/demo.gif"
Expand Down
8 changes: 3 additions & 5 deletions AlertBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
93A4C46E1E223B0B00C0962F /* AlertBar */ = {
isa = PBXGroup;
children = (
93A4C46F1E223B0B00C0962F /* AlertBar.h */,
93C0F48B1E8AC52800F15353 /* Sources */,
93A4C46F1E223B0B00C0962F /* AlertBar.h */,
93A4C4701E223B0B00C0962F /* Info.plist */,
);
path = AlertBar;
Expand Down Expand Up @@ -278,6 +278,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -323,6 +324,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -346,7 +348,6 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.sasakky.AlertBar;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -366,7 +367,6 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.sasakky.AlertBar;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -379,7 +379,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = jp.sasakky.AlertBarTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -392,7 +391,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = jp.sasakky.AlertBarTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
41 changes: 22 additions & 19 deletions Example/AlertBarExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
objects = {

/* Begin PBXBuildFile section */
930B7D7E1F78D0D2005DBCFB /* AlertBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 930B7D7D1F78D0C0005DBCFB /* AlertBar.swift */; };
93A4C4931E223C7B00C0962F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A4C4921E223C7B00C0962F /* AppDelegate.swift */; };
93A4C4951E223C7B00C0962F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A4C4941E223C7B00C0962F /* ViewController.swift */; };
93A4C4981E223C7B00C0962F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 93A4C4961E223C7B00C0962F /* Main.storyboard */; };
93A4C49A1E223C7B00C0962F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 93A4C4991E223C7B00C0962F /* Assets.xcassets */; };
93A4C49D1E223C7B00C0962F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 93A4C49B1E223C7B00C0962F /* LaunchScreen.storyboard */; };
93C0F48A1E8AC48500F15353 /* AlertBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93C0F4891E8AC48500F15353 /* AlertBar.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
930B7D7D1F78D0C0005DBCFB /* AlertBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertBar.swift; sourceTree = "<group>"; };
93A4C48F1E223C7B00C0962F /* AlertBarExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AlertBarExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
93A4C4921E223C7B00C0962F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
93A4C4941E223C7B00C0962F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
93A4C4971E223C7B00C0962F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
93A4C4991E223C7B00C0962F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
93A4C49C1E223C7B00C0962F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
93A4C49E1E223C7B00C0962F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
93C0F4891E8AC48500F15353 /* AlertBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AlertBar.swift; path = ../../../AlertBar/Sources/AlertBar.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -37,6 +37,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
930B7D7C1F78D0C0005DBCFB /* Sources */ = {
isa = PBXGroup;
children = (
930B7D7D1F78D0C0005DBCFB /* AlertBar.swift */,
);
name = Sources;
path = ../../Sources;
sourceTree = "<group>";
};
93A4C4861E223C7B00C0962F = {
isa = PBXGroup;
children = (
Expand All @@ -56,25 +65,17 @@
93A4C4911E223C7B00C0962F /* AlertBarExample */ = {
isa = PBXGroup;
children = (
930B7D7C1F78D0C0005DBCFB /* Sources */,
93A4C4921E223C7B00C0962F /* AppDelegate.swift */,
93A4C4941E223C7B00C0962F /* ViewController.swift */,
93A4C4A41E223CDB00C0962F /* Sources */,
93A4C4961E223C7B00C0962F /* Main.storyboard */,
93A4C4991E223C7B00C0962F /* Assets.xcassets */,
93A4C49B1E223C7B00C0962F /* LaunchScreen.storyboard */,
93A4C49E1E223C7B00C0962F /* Info.plist */,
93A4C49B1E223C7B00C0962F /* LaunchScreen.storyboard */,
93A4C4961E223C7B00C0962F /* Main.storyboard */,
93A4C4941E223C7B00C0962F /* ViewController.swift */,
);
path = AlertBarExample;
sourceTree = "<group>";
};
93A4C4A41E223CDB00C0962F /* Sources */ = {
isa = PBXGroup;
children = (
93C0F4891E8AC48500F15353 /* AlertBar.swift */,
);
path = Sources;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -134,8 +135,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
93A4C49D1E223C7B00C0962F /* LaunchScreen.storyboard in Resources */,
93A4C49A1E223C7B00C0962F /* Assets.xcassets in Resources */,
93A4C49D1E223C7B00C0962F /* LaunchScreen.storyboard in Resources */,
93A4C4981E223C7B00C0962F /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -147,9 +148,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
93A4C4951E223C7B00C0962F /* ViewController.swift in Sources */,
93C0F48A1E8AC48500F15353 /* AlertBar.swift in Sources */,
930B7D7E1F78D0D2005DBCFB /* AlertBar.swift in Sources */,
93A4C4931E223C7B00C0962F /* AppDelegate.swift in Sources */,
93A4C4951E223C7B00C0962F /* ViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -275,7 +276,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = jp.sasakky.AlertBarExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -288,7 +290,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = jp.sasakky.AlertBarExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
10 changes: 5 additions & 5 deletions Example/AlertBarExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ import UIKit
class ViewController: UIViewController {

@IBAction func tapSuccess(_ sender: AnyObject) {
AlertBar.show(.success, message: "This is a Success message.")
AlertBar.show(type: .success, message: "This is a Success message.")
}

@IBAction func tapError(_ sender: AnyObject) {
AlertBar.show(error: NSError(domain: "Page not found", code: 404, userInfo: nil), duration: 3)
}

@IBAction func tapNotice(_ sender: AnyObject) {
AlertBar.show(.notice, message: "This is a Notice message.", completion: { () -> Void in
AlertBar.show(type: .notice, message: "This is a Notice message.", completion: { () -> Void in
print("Noticed")
})
}

@IBAction func tapWarning(_ sender: AnyObject) {
AlertBar.show(.warning, message: "This is a Warning message.")
AlertBar.show(type: .warning, message: "This is a Warning message.")
}

@IBAction func tapInfo(_ sender: AnyObject) {
AlertBar.show(.info, message: "This is an Info message.")
AlertBar.show(type: .info, message: "This is an Info message.", option: .init(shouldConsiderSafeArea: false, isStretchable: true, textAlignment: .right))
}

@IBAction func tapCustom(_ sender: AnyObject) {
AlertBar.show(.custom(UIColor.lightGray, UIColor.black), message: "This is a Custom message.", duration: 5)
AlertBar.show(type: .custom(UIColor.lightGray, UIColor.black), message: "This is a Custom message. \nlong \nlong \nlong \nlong \nlong \nlong \nlong message", duration: 5, option: .init(isStretchable: true, textAlignment: .center))
}

override var prefersStatusBarHidden : Bool {
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

sort: sort-src sort-example

sort-src:
- ./scripts/sort-Xcode-project-file "./AlertBar.xcodeproj"

sort-example:
- ./scripts/sort-Xcode-project-file "./Example/AlertBarExample.xcodeproj"
74 changes: 57 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

An easy alert on status bar.

![demo](./assets/demo.gif)
| Demo |
| :---: |
| ![demo](./assets/demo.gif) |

## Usage
### Import
Expand All @@ -23,36 +25,74 @@ AlertBar has default types:
- warning
- info

```
AlertBar.show(.success, message: "This is a Success message.")
```swift
AlertBar.show(type: .success, message: "This is a Success message.")
```

And you can customize the background and text colors of AlertBar.
Select `Custom` type and set background and text colors as UIColor: `.Custom(BackgroundColor, TextColor)`
Select `custom` type and set background and text colors as UIColor: `.custom(BackgroundColor, TextColor)`

```
AlertBar.show(.custom(.lightGray, .black), message: "This is a Custom message.")
```swift
AlertBar.show(type: .custom(.lightGray, .black), message: "This is a Custom message.")
```

#### Alert duration
AlertBar accepts to custom alert duration.
```
AlertBar.show(.success, message: "This is a Success message.", duration: 10)
```swift
AlertBar.show(type: .success, message: "This is a Success message.", duration: 10)
```

### Custom Options
#### TextAlignment
AlertBar accepts to custom text alignment.
NOTE: This option is global.
### AlertBar Options

AlertBar accepts options follows:

- Consider Safe Area
- Stretch bar
- TextAlignment

Use `setDefault` method to set default option.
```swift
let option = AlertBar.Option(
shouldConsiderSafeArea: true,
isStretchable: true,
textAlignment: .center
)
AlertBar.setDefault(option: option)
```
AlertBar.textAlignment = .center

Or set parameter of `show` method to each AlertBar.
```swift
let option = AlertBar.Option(
shouldConsiderSafeArea: true,
isStretchable: true,
textAlignment: .center
)
AlertBar.show(type: .success, message: "This is AlertBar!", option: option)
```

## Requirements
### Consider Safe Area
The Safe Area is adopted from iOS 11 and AlertBar can change whether to consider SafeArea or not.

- Swift 3.x
- iOS 8.0+
- ARC
`AlertBar.Option#shouldConsiderSafeArea: Bool`
is set to `true` by default.

| `shouldConsiderSafeArea == true` | `shouldConsiderSafeArea == false` |
| :---: | :---: |
| ![true](./assets/shouldConsiderSafeArea_true.png) | ![false](./assets/shouldConsiderSafeArea_false.png) |

### Stretch bar
AlertBar can stretch the bar if the message needs the multi lines.

`AlertBar.Option#isStretchable: Bool`
is set to `false` by default.

| `isStretchable == true` | `isStretchable == false` |
| :---: | :---: |
| ![true](./assets/isStretchable_true.png) | ![false](./assets/isStretchable_false.png) |


#### TextAlignment
AlertBar accepts to custom text alignment.

## Installation
### CocoaPods
Expand Down
Loading

0 comments on commit 5fb5b94

Please sign in to comment.