diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/NYAlertViewController/NYAlertViewController.h b/NYAlertViewController/NYAlertViewController.h index 45d8ec9..4562fca 100644 --- a/NYAlertViewController/NYAlertViewController.h +++ b/NYAlertViewController/NYAlertViewController.h @@ -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 diff --git a/NYAlertViewController/NYAlertViewController.m b/NYAlertViewController/NYAlertViewController.m index c88982d..52e42e9 100644 --- a/NYAlertViewController/NYAlertViewController.m +++ b/NYAlertViewController/NYAlertViewController.m @@ -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; diff --git a/NYAlertViewController/include/NYAlertViewControllerUmbrellaHeader.h b/NYAlertViewController/include/NYAlertViewControllerUmbrellaHeader.h new file mode 100644 index 0000000..de691ec --- /dev/null +++ b/NYAlertViewController/include/NYAlertViewControllerUmbrellaHeader.h @@ -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 */ diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..c974d65 --- /dev/null +++ b/Package.swift @@ -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") + ] + ) + ] +) diff --git a/README.md b/README.md index 64a454a..f827aaa 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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.