Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift-package support #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions NYAlertViewController/NYAlertViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, nullable) NSString *message;

/**
The attributed message displayed under the alert view's title
*/
@property (nonatomic, strong) NSAttributedString *attributedMessage;

/**
The custom view displayed in the presented alert view

Expand Down
5 changes: 5 additions & 0 deletions NYAlertViewController/NYAlertViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ - (void)setMessage:(NSString *)message {
self.view.messageTextView.text = message;
}

- (void)setAttributedMessage:(NSAttributedString *)attributedMessage {
_attributedMessage = attributedMessage;
self.view.messageTextView.attributedText = attributedMessage;
}

- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectZero];
textField.borderStyle = UITextBorderStyleRoundedRect;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Header.h
//
//
// Created by Ettore Gallina on 13/04/23.
//

#ifndef NYAlertViewControllerUmbrellaHeader_h
#define NYAlertViewControllerUmbrellaHeader_h

#import "../NYAlertAction.h"
#import "../NYAlertActionConfiguration.h"
#import "../NYAlertViewController.h"
#import "../NYAlertViewControllerConfiguration.h"
#import "../NYAlertViewControllerTransitionStyle.h"

#endif /* NYAlertViewControllerUmbrellaHeader_h */
34 changes: 34 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "NYAlertViewController",
platforms: [
.iOS(.v11)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "NYAlertViewController",
targets: ["NYAlertViewController"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "NYAlertViewController",
dependencies: [],
path: "NYAlertViewController",
cSettings: [
.headerSearchPath("."),
.headerSearchPath("Private")
]
)
]
)
72 changes: 68 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

NYAlertViewController is a replacement for UIAlertController/UIAlertView with support for content views and UI customization.

![Swift-Package](https://img.shields.io/badge/Swift--Package-Compatible-green)
![Cocoa-Pods](https://img.shields.io/badge/CocoaPods-Compatible-green)

![Example](https://github.com/nealyoung/NYAlertViewController/raw/master/header.png)

### Features
Expand All @@ -11,17 +14,31 @@ NYAlertViewController is a replacement for UIAlertController/UIAlertView with su
* Easily add text fields with simple API identical to UIAlertController
* Choose between fade (similar to UIAlertController) or slide transition animations

### Installation
## Installation
#### Manual
Add the files to your project manually by dragging the NYAlertViewController directory into your Xcode project.

#### CocoaPods
Add `pod 'NYAlertViewController'` to your Podfile, and run `pod install`.

### Usage Example
An Objective-C example project demonstrating customization options is included in the NYAlertViewControllerDemo directory.
#### Swift Package Manager
Open your project in Xcode

1. Click "File" -> "Add Packages..."
2. Paste the following URL: https://github.com/gallinaettore/NYAlertViewController

You can specify the dependency in `Package.swift` by adding this:

```swift
.package(url: "https://github.com/gallinaettore/NYAlertViewController.git", .upToNextMajor(from: "2.0.1"))
```


## Usage Example


#### Objective-C
An Objective-C example project demonstrating customization options is included in the NYAlertViewControllerDemo directory.

```objc
// Import the class and create an NYAlertViewController instance
Expand Down Expand Up @@ -71,5 +88,52 @@ alertViewController.alertViewContentView = iconImageView;
[self presentViewController:alertViewController animated:YES completion:nil];
```

### License
#### Swift
An Swift example project demonstrating customization options.

```swift
// Import the class and create an NYAlertViewController instance
import NYAlertViewController

// ...

// Set a title and message
let title = "Location Permission"
let message = "Set the alertViewContentView property to add custom views to the alert view"

// Customize appearance as desired
let configuration = NYAlertViewControllerConfiguration()
configuration.contentViewInset = UIEdgeInsets(top: 12, left: 8, bottom: 8, right: 8)
configuration.alertViewBackgroundColor = UIColor(red: 0.23, green: 0.23, blue: 0.27, alpha: 1.0)
configuration.separatorColor = UIColor(red: 0.16, green: 0.16, blue: 0.2, alpha: 1.0)
configuration.titleTextColor = .white
configuration.messageTextColor = .white

configuration.buttonConfiguration = NYAlertActionConfiguration()
configuration.buttonConfiguration.titleColor = .white

configuration.cancelButtonConfiguration.titleColor = .white

// Set up alert actions
let cancelAction = NYAlertAction(title: "Later", style: .cancel, handler: nil)
let okAction = NYAlertAction(title: "Ok", style: .default) { action in
self.doSomething()
}

let alertViewController = NYAlertViewController(options: configuration,
title: title,
message: message,
actions: [cancelAction, okAction])

// Optionally add a content view
let iconImageView = UIImageView(image: UIImage(named: "MapIcon"))
iconImageView.contentMode = .scaleAspectFit
iconImageView.heightAnchor.constraint(equalToConstant: 60.0).isActive = true
alertViewController.alertViewContentView = iconImageView

// Present the alert view controller
self.present(alertViewController, animated: true, completion: nil)
```

## License
This project is released under the MIT License.