├── image
├── 1.png
├── 2.png
├── 3.png
├── 4.png
├── 5.png
├── 6.png
├── 7.png
├── 8.png
├── 9.png
├── 10.png
├── 11.png
├── 12.png
├── 13.png
├── 14.png
└── 15.png
├── YWAlertViewDemo
├── .DS_Store
├── YWAlertViewDemo
│ ├── Assets.xcassets
│ │ ├── Contents.json
│ │ ├── 17938752.imageset
│ │ │ ├── 17938752.jpeg
│ │ │ └── Contents.json
│ │ ├── 105459445.imageset
│ │ │ ├── 105459445@2x.png
│ │ │ ├── 105459445@3x.png
│ │ │ └── Contents.json
│ │ ├── bg_fuweus.imageset
│ │ │ ├── bg_fuweus@2x.png
│ │ │ ├── bg_fuweus@3x.png
│ │ │ └── Contents.json
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── ViewController.h
│ ├── YWTheme.h
│ ├── AppDelegate.h
│ ├── YWTimeViewController.h
│ ├── main.m
│ ├── YWTheme.m
│ ├── Info.plist
│ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ ├── YWTimeViewController.m
│ ├── AppDelegate.m
│ └── ViewController.m
├── YWAlertViewDemo.xcodeproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata
│ │ └── xcbaselines
│ │ └── DAD13EE72133DA4000106659.xcbaseline
│ │ ├── A203552C-CE33-45E1-8FE2-C1F8CE080187.plist
│ │ └── Info.plist
├── YWAlertViewDemoTests
│ ├── Info.plist
│ └── YWAlertViewDemoTests.m
└── YWAlertViewDemoUITests
│ ├── Info.plist
│ └── YWAlertViewDemoUITests.m
├── YWAlertView
├── YWAlertView.bundle
│ ├── yw_alter_close@2x.png
│ └── yw_alter_close@3x.png
├── YWSingleGeneralModel.m
├── YWContainerViewController.h
├── YWSingleGeneralModel.h
├── UIImage+YW.h
├── UIView+Autolayout.h
├── YWDatePicker.h
├── YWAddressPicker.h
├── YWSingleGeneralPicker.h
├── YWContainerViewController.m
├── YWAlert.h
├── YWActionSheet.h
├── YWAddressModel.h
├── YWAlertViewHelper.h
├── YWAddressModel.m
├── UIView+Autolayout.m
├── YWAlertViewHelper.m
├── UIImage+YW.m
├── YWAlertView.h
├── YWAlertViewProtocol.h
├── NSDate+YW.h
├── YWAlertView.m
├── NSDate+YW.m
├── YWSingleGeneralPicker.m
└── YWActionSheet.m
├── LICENSE
├── .gitignore
├── YWAlertView.podspec
└── README.md
/image/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/1.png
--------------------------------------------------------------------------------
/image/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/2.png
--------------------------------------------------------------------------------
/image/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/3.png
--------------------------------------------------------------------------------
/image/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/4.png
--------------------------------------------------------------------------------
/image/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/5.png
--------------------------------------------------------------------------------
/image/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/6.png
--------------------------------------------------------------------------------
/image/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/7.png
--------------------------------------------------------------------------------
/image/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/8.png
--------------------------------------------------------------------------------
/image/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/9.png
--------------------------------------------------------------------------------
/image/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/10.png
--------------------------------------------------------------------------------
/image/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/11.png
--------------------------------------------------------------------------------
/image/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/12.png
--------------------------------------------------------------------------------
/image/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/13.png
--------------------------------------------------------------------------------
/image/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/14.png
--------------------------------------------------------------------------------
/image/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/image/15.png
--------------------------------------------------------------------------------
/YWAlertViewDemo/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertViewDemo/.DS_Store
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/YWAlertView/YWAlertView.bundle/yw_alter_close@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertView/YWAlertView.bundle/yw_alter_close@2x.png
--------------------------------------------------------------------------------
/YWAlertView/YWAlertView.bundle/yw_alter_close@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertView/YWAlertView.bundle/yw_alter_close@3x.png
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/17938752.imageset/17938752.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/17938752.imageset/17938752.jpeg
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/105459445.imageset/105459445@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/105459445.imageset/105459445@2x.png
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/105459445.imageset/105459445@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/105459445.imageset/105459445@3x.png
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/bg_fuweus.imageset/bg_fuweus@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/bg_fuweus.imageset/bg_fuweus@2x.png
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/bg_fuweus.imageset/bg_fuweus@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flyOfYW/YWAlertView/HEAD/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/bg_fuweus.imageset/bg_fuweus@3x.png
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/YWAlertView/YWSingleGeneralModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWSingleGeneralModel.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by Mr.Yao on 2020/2/23.
6 | // Copyright © 2020 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWSingleGeneralModel.h"
10 |
11 | @implementation YWSingleGeneralModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/YWTheme.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWTheme.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/29.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YWAlertViewProtocol.h"
11 |
12 | @interface YWTheme : NSObject
13 |
14 | @end
15 |
--------------------------------------------------------------------------------
/YWAlertView/YWContainerViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWContainerViewController.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/29.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface YWContainerViewController : UIViewController
12 | @property (nonatomic, strong) UIView *alertView;
13 | @end
14 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/YWTimeViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWTimeViewController.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/11/28.
6 | // Copyright © 2018 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | NS_ASSUME_NONNULL_BEGIN
12 |
13 | @interface YWTimeViewController : UIViewController
14 |
15 | @end
16 |
17 | NS_ASSUME_NONNULL_END
18 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/17938752.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "17938752.jpeg",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/105459445.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "105459445@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "105459445@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/bg_fuweus.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "bg_fuweus@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "bg_fuweus@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/YWAlertView/YWSingleGeneralModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWSingleGeneralModel.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by Mr.Yao on 2020/2/23.
6 | // Copyright © 2020 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | NS_ASSUME_NONNULL_BEGIN
12 |
13 | @interface YWSingleGeneralModel : NSObject
14 | @property (nonatomic, assign) NSInteger idc;
15 | @property (nonatomic, copy) NSString *displayName;
16 | @property (nonatomic, copy) NSString *displayMenu;
17 |
18 | @end
19 |
20 | NS_ASSUME_NONNULL_END
21 |
--------------------------------------------------------------------------------
/YWAlertView/UIImage+YW.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+YW.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/29.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (YW)
12 | /// 获取屏幕截图
13 | ///
14 | /// @return 屏幕截图图像
15 | + (UIImage *)yw_screenShot;
16 | + (UIImage *)yw_blurImage:(UIImage *)image blur:(CGFloat)blur;
17 | + (UIImage *)getImageOnBundle:(NSString *)imageName
18 | ofType:(NSString *)type
19 | forClass:(Class)calss;
20 | @end
21 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo.xcodeproj/xcshareddata/xcbaselines/DAD13EE72133DA4000106659.xcbaseline/A203552C-CE33-45E1-8FE2-C1F8CE080187.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | classNames
6 |
7 | YWAlertViewDemoTests
8 |
9 | testPerformanceExample
10 |
11 | com.apple.XCTPerformanceMetric_WallClockTime
12 |
13 | baselineAverage
14 | 0.012146
15 | baselineIntegrationDisplayName
16 | Local Baseline
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemoTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemoUITests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/YWTheme.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWTheme.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/29.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWTheme.h"
10 |
11 | @implementation YWTheme
12 | - (UIColor *)alertTitleViewColor{
13 | return [UIColor greenColor];
14 | }
15 | - (UIColor *)alertCancelColor{
16 | return [UIColor redColor];
17 | }
18 | - (UIImage *)alertBackgroundView{
19 | return [UIImage imageNamed:@"105459445"];
20 | }
21 | - (CGFloat)alterBackgroundViewArticulation{
22 | return 0.5;
23 | }
24 | - (NSString *)alertMessageFontWithName{
25 | return @"AmericanTypewriter";
26 | }
27 | - (NSString *)alertTitleFontWithName{
28 | return @"Baskerville-SemiBoldItalic";
29 | }
30 | - (void)dealloc{
31 | NSLog(@"%s",__func__);
32 | }
33 | @end
34 |
--------------------------------------------------------------------------------
/YWAlertView/UIView+Autolayout.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+Autolayout.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIView (Autolayout)
12 | -(void)addConstraint:(NSLayoutAttribute)attribute equalTo:(UIView *)to offset:(CGFloat)offset;
13 | -(NSLayoutConstraint *)addConstraintAndReturn:(NSLayoutAttribute)attribute equalTo:(UIView *)to toAttribute:(NSLayoutAttribute)toAttribute offset:(CGFloat)offset;
14 | -(void)addConstraint:(NSLayoutAttribute)attribute equalTo:(UIView *)to toAttribute:(NSLayoutAttribute)toAttribute offset:(CGFloat)offset;
15 | - (void)removeAllAutoLayout;
16 | - (void)removeAutoLayout:(NSLayoutConstraint *)constraint;
17 |
18 | - (NSLayoutConstraint *)getAutoLayoutByIdentifier:(NSString *)identifier;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/YWAlertView/YWDatePicker.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWDatePicker.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/31.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YWAlertViewProtocol.h"
11 |
12 | @interface YWDatePicker : UIView
13 | @property (nonatomic, weak) _Nullable id delegate;
14 |
15 | - (instancetype _Nullable)initWithTitle:(nullable NSString *)title
16 | delegate:(id _Nullable)delegate
17 | footStyle:(YWAlertPublicFootStyle)footStyle
18 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
19 | mode:(NSInteger)mode//扩展date具体位置
20 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
21 | okButtonTitles:(nullable NSString *)sureButtonTitles
22 | handler:(nullable void(^)(NSInteger buttonIndex,
23 | id _Nullable value))handler;
24 | @end
25 |
--------------------------------------------------------------------------------
/YWAlertView/YWAddressPicker.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWAddressPicker.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/12/5.
6 | // Copyright © 2018 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YWAlertViewProtocol.h"
11 |
12 | NS_ASSUME_NONNULL_BEGIN
13 |
14 | @interface YWAddressPicker : UIView
15 | @property (nonatomic, weak) _Nullable id delegate;
16 | - (instancetype _Nullable)initWithTitle:(nullable NSString *)title
17 | delegate:(id _Nullable)delegate
18 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
19 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
20 | okButtonTitles:(nullable NSString *)sureButtonTitles
21 | handler:(nullable void(^)(NSInteger buttonIndex,
22 | id _Nullable value))handler;
23 | @end
24 |
25 | NS_ASSUME_NONNULL_END
26 |
--------------------------------------------------------------------------------
/YWAlertView/YWSingleGeneralPicker.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWSingleGeneralPicker.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by Mr.Yao on 2020/2/23.
6 | // Copyright © 2020 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YWAlertViewProtocol.h"
11 | @class YWSingleGeneralModel;
12 |
13 | NS_ASSUME_NONNULL_BEGIN
14 |
15 | @interface YWSingleGeneralPicker : UIView
16 | @property (nonatomic, weak) _Nullable id delegate;
17 | - (instancetype _Nullable)initWithTitle:(nullable NSString *)title
18 | delegate:(id _Nullable)delegate
19 | dataSource:(NSArray *)dataSource
20 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
21 | okButtonTitles:(nullable NSString *)sureButtonTitles
22 | handler:(nullable void(^)(NSInteger buttonIndex,
23 | id _Nullable value))handler;
24 | @end
25 | NS_ASSUME_NONNULL_END
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/YWAlertView/YWContainerViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWContainerViewController.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/29.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWContainerViewController.h"
10 | #import "UIView+Autolayout.h"
11 |
12 | @interface YWContainerViewController ()
13 |
14 | @end
15 |
16 | @implementation YWContainerViewController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 |
21 | [self.view addSubview:self.alertView];
22 |
23 | self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
24 |
25 | [self.alertView addConstraint:NSLayoutAttributeLeft equalTo:self.view offset:0];
26 | [self.alertView addConstraint:NSLayoutAttributeRight equalTo:self.view offset:0];
27 | [self.alertView addConstraint:NSLayoutAttributeTop equalTo:self.view offset:0];
28 | [self.alertView addConstraint:NSLayoutAttributeBottom equalTo:self.view offset:0];
29 | }
30 | - (void)viewDidDisappear:(BOOL)animated{
31 | [super viewDidDisappear:animated];
32 | }
33 | - (void)dealloc{
34 | NSLog(@"%s",__func__);
35 | }
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/YWAlertView/YWAlert.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlert.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YWAlertViewProtocol.h"
11 |
12 | @interface YWAlert : UIView
13 |
14 | @property (nonatomic, weak) _Nullable id delegate;
15 |
16 | @property (nonatomic, assign, readonly) YWAlertPublicFootStyle footStyle;
17 | @property (nonatomic, assign, readonly) YWAlertPublicBodyStyle bodyStyle;
18 |
19 |
20 | - (instancetype _Nullable )initWithTitle:(nullable NSString *)title
21 | message:(nullable NSString *)message
22 | delegate:(id _Nullable )delegate
23 | footStyle:(YWAlertPublicFootStyle)footStyle
24 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
25 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
26 | otherButtonTitles:(nullable NSArray *)otherButtonTitles
27 | handler:(nullable void(^)(NSInteger buttonIndex,
28 | id _Nullable value))handler;
29 | @end
30 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemoTests/YWAlertViewDemoTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlertViewDemoTests.m
3 | // YWAlertViewDemoTests
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "NSDate+YW.h"
11 |
12 | @interface YWAlertViewDemoTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation YWAlertViewDemoTests
17 |
18 | - (void)setUp {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown {
24 | // Put teardown code here. This method is called after the invocation of each test method in the class.
25 | [super tearDown];
26 | }
27 |
28 | - (void)testExample {
29 |
30 |
31 | }
32 |
33 | - (void)testPerformanceExample {
34 | // This is an example of a performance test case.
35 | [self measureBlock:^{
36 | // Put the code you want to measure the time of here.
37 | long long temp = 1537499110;
38 | for (int i = 0; i < 20; i ++) {
39 | [NSDate dateYYYYMMDDByTimeStamp:temp];
40 | }
41 | }];
42 | }
43 |
44 | @end
45 |
--------------------------------------------------------------------------------
/YWAlertView/YWActionSheet.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWActionSheet.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/30.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YWAlertViewProtocol.h"
11 |
12 | NS_ASSUME_NONNULL_BEGIN
13 | @interface YWActionSheet : UIView
14 |
15 | @property (nonatomic, weak) _Nullable id delegate;
16 |
17 | - (instancetype _Nullable )initWithTitle:(nullable NSString *)title
18 | message:(nullable NSString *)message
19 | delegate:(id _Nullable )delegate
20 | footStyle:(YWAlertPublicFootStyle)footStyle
21 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
22 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
23 | otherButtonTitles:(nullable NSArray *)otherButtonTitles
24 | handler:(nullable void(^)(NSInteger buttonIndex,
25 | id _Nullable value))handler;
26 | @end
27 |
28 | @interface YWActionSheetButtion : UIView
29 | - (instancetype)initWithTitle:(NSString *)title;
30 | @end
31 | NS_ASSUME_NONNULL_END
32 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo.xcodeproj/xcshareddata/xcbaselines/DAD13EE72133DA4000106659.xcbaseline/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | runDestinationsByUUID
6 |
7 | A203552C-CE33-45E1-8FE2-C1F8CE080187
8 |
9 | localComputer
10 |
11 | busSpeedInMHz
12 | 100
13 | cpuCount
14 | 1
15 | cpuKind
16 | Intel Core i5
17 | cpuSpeedInMHz
18 | 1400
19 | logicalCPUCoresPerPackage
20 | 4
21 | modelCode
22 | MacBookAir6,2
23 | physicalCPUCoresPerPackage
24 | 2
25 | platformIdentifier
26 | com.apple.platform.macosx
27 |
28 | targetArchitecture
29 | x86_64
30 | targetDevice
31 |
32 | modelCode
33 | iPhone10,5
34 | platformIdentifier
35 | com.apple.platform.iphonesimulator
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemoUITests/YWAlertViewDemoUITests.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlertViewDemoUITests.m
3 | // YWAlertViewDemoUITests
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface YWAlertViewDemoUITests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation YWAlertViewDemoUITests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 |
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 |
22 | // In UI tests it is usually best to stop immediately when a failure occurs.
23 | self.continueAfterFailure = NO;
24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
25 | [[[XCUIApplication alloc] init] launch];
26 |
27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
28 | }
29 |
30 | - (void)tearDown {
31 | // Put teardown code here. This method is called after the invocation of each test method in the class.
32 | [super tearDown];
33 | }
34 |
35 | - (void)testExample {
36 | // Use recording to get started writing UI tests.
37 | // Use XCTAssert and related functions to verify your tests produce the correct results.
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/YWAlertView/YWAddressModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWAddressModel.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/12/5.
6 | // Copyright © 2018 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | NS_ASSUME_NONNULL_BEGIN
12 |
13 |
14 | /// 省
15 | @interface YWProvinceModel : NSObject
16 | /** 省对应的code或id */
17 | @property (nonatomic, copy) NSString *code;
18 | /** 省的名称 */
19 | @property (nonatomic, copy) NSString *name;
20 | /** 省的索引 */
21 | @property (nonatomic, assign) NSInteger index;
22 | /** 城市数组 */
23 | @property (nonatomic, strong) NSArray *citylist;
24 |
25 | @end
26 |
27 | /// 市
28 | @interface YWCityModel : NSObject
29 | /** 市对应的code或id */
30 | @property (nonatomic, copy) NSString *code;
31 | /** 市的名称 */
32 | @property (nonatomic, copy) NSString *name;
33 | /** 市的索引 */
34 | @property (nonatomic, assign) NSInteger index;
35 | /** 地区数组 */
36 | @property (nonatomic, strong) NSArray *arealist;
37 |
38 | @end
39 |
40 | /// 区
41 | @interface YWAreaModel : NSObject
42 | /** 区对应的code或id */
43 | @property (nonatomic, copy) NSString *code;
44 | /** 区的名称 */
45 | @property (nonatomic, copy) NSString *name;
46 | /** 区的索引 */
47 | @property (nonatomic, assign) NSInteger index;
48 |
49 | @end
50 |
51 |
52 | /// 结果返回的model
53 | @interface YWResultModel : NSObject
54 | /** 区model */
55 | @property (nonatomic, strong) YWAreaModel *area;
56 | /** 市model */
57 | @property (nonatomic, strong) YWCityModel *city;
58 | /** 省model */
59 | @property (nonatomic, strong) YWProvinceModel *province;
60 |
61 | @end
62 |
63 | NS_ASSUME_NONNULL_END
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xccheckout
23 | *.xcscmblueprint
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 | *.ipa
28 | *.dSYM.zip
29 | *.dSYM
30 |
31 | # CocoaPods
32 | #
33 | # We recommend against adding the Pods directory to your .gitignore. However
34 | # you should judge for yourself, the pros and cons are mentioned at:
35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
36 | #
37 | # Pods/
38 |
39 | # Carthage
40 | #
41 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
42 | # Carthage/Checkouts
43 |
44 | Carthage/Build
45 |
46 | # fastlane
47 | #
48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
49 | # screenshots whenever they are needed.
50 | # For more information about the recommended setup visit:
51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
52 |
53 | fastlane/report.xml
54 | fastlane/Preview.html
55 | fastlane/screenshots/**/*.png
56 | fastlane/test_output
57 |
58 | # Code Injection
59 | #
60 | # After new code Injection tools there's a generated folder /iOSInjectionProject
61 | # https://github.com/johnno1962/injectionforxcode
62 |
63 | iOSInjectionProject/
64 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/YWAlertView/YWAlertViewHelper.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlertViewHelper.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/30.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 |
10 | #define YWAlertScreenW [UIScreen mainScreen].bounds.size.width
11 | #define YWAlertScreenH [UIScreen mainScreen].bounds.size.height
12 |
13 | //判断是否是刘海屏
14 | #define IS_LIU_HAI_SCREEN ({\
15 | BOOL isBangsScreen = NO; \
16 | if (@available(iOS 11.0, *)) { \
17 | UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \
18 | isBangsScreen = window.safeAreaInsets.bottom > 0; \
19 | } \
20 | isBangsScreen; \
21 | })
22 |
23 | //刘海屏底部的高度
24 | #define kDevice_TABBARBOTTOM ({\
25 | CGFloat isBangsScreen = 0; \
26 | if (@available(iOS 11.0, *)) { \
27 | UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \
28 | isBangsScreen = window.safeAreaInsets.bottom; \
29 | } \
30 | isBangsScreen; \
31 | })
32 |
33 |
34 |
35 |
36 |
37 | //#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
38 |
39 | #define IS_PAD (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)
40 |
41 | #define DefaultTranslucenceColor [UIColor colorWithRed:255 / 255.0f green:255 / 255.0 blue:255 / 255.0 alpha:0.98]
42 | #define DefaultLineTranslucenceColor [UIColor colorWithRed:219 / 255.0f green:219 / 255.0 blue:219 / 255.0 alpha:0.7]
43 |
44 | static const float titleViewHeight = 40;
45 | static const float butttionViewHeight = 40;
46 |
47 |
48 | #import
49 |
50 | @interface YWAlertViewHelper : UIView
51 | + (UIViewController*)currentViewController;
52 | // 通过递归拿到当前控制器
53 | + (UIViewController*)currentViewControllerFrom:(UIViewController*)viewController;
54 | + (UIWindow *)getWindow;
55 | @end
56 |
--------------------------------------------------------------------------------
/YWAlertView/YWAddressModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWAddressModel.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/12/5.
6 | // Copyright © 2018 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWAddressModel.h"
10 |
11 | @implementation YWProvinceModel
12 |
13 | - (id)copyWithZone:(NSZone *)zone{
14 | YWProvinceModel * model = [[YWProvinceModel allocWithZone:zone] init];
15 | model.code = self.code;
16 | model.name = self.name;
17 | model.index = self.index;
18 | return model;
19 | }
20 | - (id)mutableCopyWithZone:(NSZone *)zone{
21 | YWProvinceModel * model = [[YWProvinceModel allocWithZone:zone] init];
22 | model.code = self.code;
23 | model.name = self.name;
24 | model.index = self.index;
25 | return model;
26 | }
27 | @end
28 |
29 |
30 | @implementation YWCityModel
31 | - (id)copyWithZone:(NSZone *)zone{
32 | YWProvinceModel * model = [[YWProvinceModel allocWithZone:zone] init];
33 | model.code = self.code;
34 | model.name = self.name;
35 | model.index = self.index;
36 | return model;
37 | }
38 | - (id)mutableCopyWithZone:(NSZone *)zone{
39 | YWProvinceModel * model = [[YWProvinceModel allocWithZone:zone] init];
40 | model.code = self.code;
41 | model.name = self.name;
42 | model.index = self.index;
43 | return model;
44 | }
45 | @end
46 |
47 |
48 | @implementation YWAreaModel
49 | - (id)copyWithZone:(NSZone *)zone{
50 | YWProvinceModel * model = [[YWProvinceModel allocWithZone:zone] init];
51 | model.code = self.code;
52 | model.name = self.name;
53 | model.index = self.index;
54 | return model;
55 | }
56 | - (id)mutableCopyWithZone:(NSZone *)zone{
57 | YWProvinceModel * model = [[YWProvinceModel allocWithZone:zone] init];
58 | model.code = self.code;
59 | model.name = self.name;
60 | model.index = self.index;
61 | return model;
62 | }
63 | @end
64 |
65 | @implementation YWResultModel
66 | @end
67 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/YWTimeViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWTimeViewController.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/11/28.
6 | // Copyright © 2018 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWTimeViewController.h"
10 | #import "NSDate+YW.h"
11 |
12 | @interface YWTimeViewController ()
13 | @property (weak, nonatomic) IBOutlet UILabel *yesterdayLabel;
14 | @property (weak, nonatomic) IBOutlet UITextField *dayNum;
15 | @property (weak, nonatomic) IBOutlet UILabel *dayLabel;
16 |
17 | @property (weak, nonatomic) IBOutlet UILabel *monthLastDataLabel;
18 | @property (weak, nonatomic) IBOutlet UILabel *quarterLasrDateLabel;
19 |
20 | @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
21 | @property (weak, nonatomic) IBOutlet UILabel *dateLabel;
22 | @property (weak, nonatomic) IBOutlet UILabel *afterDateLabel;
23 | @property (weak, nonatomic) IBOutlet UITextField *numDayTF;
24 | @end
25 |
26 | @implementation YWTimeViewController
27 |
28 | - (void)viewDidLoad {
29 | [super viewDidLoad];
30 | // Do any additional setup after loading the view.
31 |
32 |
33 |
34 | self.yesterdayLabel.text = [NSString stringWithFormat:@"昨天日期 %@",[NSDate getDateOfYesterday]];
35 | self.monthLastDataLabel.text = [NSString stringWithFormat:@"本月最后一天的日期 %@",[NSDate getDateOfThisMonth]];
36 | self.quarterLasrDateLabel.text = [NSString stringWithFormat:@"本季度最后一天的日期 %@",[NSDate getTheDateOfTheLastDayOfTheQuarter]];
37 |
38 | self.dateLabel.text = [NSString stringWithFormat:@"当前日期 %@",[NSDate getDateOfNow]];
39 | self.timeLabel.text = [NSString stringWithFormat:@"当前时间戳 %lld",(long long)[NSDate getNowTimeInterval]];
40 |
41 | NSLog(@"当前月份共有%zi天",[[NSDate date] days]);
42 |
43 | }
44 |
45 | - (IBAction)tranFormAction:(id)sender {
46 | [self.dayNum endEditing:YES];
47 | self.dayLabel.text = [NSString stringWithFormat:@"日期:%@",[NSDate getTheDateBeforeSomeday:nil day:[self.dayNum.text integerValue]]];
48 | }
49 | - (IBAction)tranFormActionAfter:(id)sender {
50 | [self.numDayTF endEditing:YES];
51 | self.afterDateLabel.text = [NSString stringWithFormat:@"日期:%@",[NSDate getTheDateAfterSomeday:nil day:[self.numDayTF.text integerValue]]];
52 | }
53 | @end
54 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 |
24 | - (void)applicationWillResignActive:(UIApplication *)application {
25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
27 | }
28 |
29 |
30 | - (void)applicationDidEnterBackground:(UIApplication *)application {
31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
33 | }
34 |
35 |
36 | - (void)applicationWillEnterForeground:(UIApplication *)application {
37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
38 | }
39 |
40 |
41 | - (void)applicationDidBecomeActive:(UIApplication *)application {
42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
43 | }
44 |
45 |
46 | - (void)applicationWillTerminate:(UIApplication *)application {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/YWAlertView/UIView+Autolayout.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+Autolayout.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "UIView+Autolayout.h"
10 |
11 | @implementation UIView (Autolayout)
12 |
13 | -(void)addConstraint:(NSLayoutAttribute)attribute equalTo:(UIView *)to offset:(CGFloat)offset{
14 | [self setTranslatesAutoresizingMaskIntoConstraints:NO];
15 | [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:to attribute:attribute multiplier:1.0 constant:offset]];
16 | }
17 |
18 | -(void)addConstraint:(NSLayoutAttribute)attribute equalTo:(UIView *)to toAttribute:(NSLayoutAttribute)toAttribute offset:(CGFloat)offset{
19 | [self setTranslatesAutoresizingMaskIntoConstraints:NO];
20 | [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:to attribute:toAttribute multiplier:1.0 constant:offset]];
21 | }
22 |
23 | -(NSLayoutConstraint *)addConstraintAndReturn:(NSLayoutAttribute)attribute equalTo:(UIView *)to toAttribute:(NSLayoutAttribute)toAttribute offset:(CGFloat)offset{
24 | [self setTranslatesAutoresizingMaskIntoConstraints:NO];
25 | NSLayoutConstraint *lay = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:to attribute:toAttribute multiplier:1.0 constant:offset];
26 | [self.superview addConstraint:lay];
27 | return lay;
28 | }
29 | - (void)removeAllAutoLayout{
30 | for (NSLayoutConstraint *con in self.constraints)
31 | {
32 | [self removeConstraint:con];
33 | }
34 | }
35 |
36 | - (void)removeAutoLayout:(NSLayoutConstraint *)constraint{
37 | for (NSLayoutConstraint *con in self.superview.constraints) {
38 | if ([con isEqual:constraint]) {
39 | [self.superview removeConstraint:con];
40 | }
41 | }
42 | }
43 | - (NSLayoutConstraint *)getAutoLayoutByIdentifier:(NSString *)identifier{
44 | NSLayoutConstraint *lay = nil;
45 | for (NSLayoutConstraint *con in self.constraints)
46 | {
47 | if ([con.identifier isEqualToString:identifier]) {
48 | lay = con;
49 | break;
50 | }
51 | }
52 | return lay;
53 | }
54 |
55 | @end
56 |
--------------------------------------------------------------------------------
/YWAlertView/YWAlertViewHelper.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlertViewHelper.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/30.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWAlertViewHelper.h"
10 |
11 | @implementation YWAlertViewHelper
12 |
13 | //MARK: --- 跟控制器相关
14 | + (UIViewController*)currentViewController {
15 | UIViewController* rootViewController = [self getWindow].rootViewController;
16 | return [self currentViewControllerFrom:rootViewController];
17 | }
18 | // 通过递归拿到当前控制器
19 | + (UIViewController*)currentViewControllerFrom:(UIViewController*)viewController {
20 |
21 | if ([viewController isKindOfClass:[UINavigationController class]]) {
22 | UINavigationController* navigationController = (UINavigationController *)viewController;
23 | // 如果传入的控制器是导航控制器,则返回最后一个
24 | return [self currentViewControllerFrom:navigationController.viewControllers.lastObject];
25 | }else if([viewController isKindOfClass:[UITabBarController class]]) {
26 |
27 | UITabBarController* tabBarController = (UITabBarController *)viewController;
28 | // 如果传入的控制器是tabBar控制器,则返回选中的那个
29 | return [self currentViewControllerFrom:tabBarController.selectedViewController];
30 | }else if(viewController.presentedViewController != nil) {
31 | // 如果传入的控制器发生了modal,则就可以拿到modal的那个控制器
32 | return [self currentViewControllerFrom:viewController.presentedViewController];
33 | }else {
34 | return viewController;
35 | }
36 |
37 | }
38 |
39 | + (UIWindow *)getWindow{
40 | UIWindow *window = nil;
41 | if (@available(iOS 13.0, *))
42 | {
43 | for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes.allObjects)
44 | {
45 | if (windowScene.activationState == UISceneActivationStateForegroundActive)
46 | {
47 | for (UIWindow *w in windowScene.windows) {
48 | if (w.isKeyWindow) {
49 | window = w;
50 | break;
51 | }
52 | }
53 | break;
54 | }
55 | }
56 | if (!window) {
57 | window = [UIApplication sharedApplication].delegate.window;
58 | }
59 | }else{
60 | window = [UIApplication sharedApplication].delegate.window;
61 | }
62 | return window;
63 | }
64 |
65 | @end
66 |
--------------------------------------------------------------------------------
/YWAlertView/UIImage+YW.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+YW.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/29.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "UIImage+YW.h"
10 | #import
11 | #import "YWAlertViewHelper.h"
12 |
13 | @implementation UIImage (YW)
14 | /// 获取屏幕截图
15 | ///
16 | /// @return 屏幕截图图像
17 | + (UIImage *)yw_screenShot{
18 | // 1. 获取到窗口
19 | UIWindow *window = [YWAlertViewHelper getWindow];
20 |
21 | // 2. 开始上下文
22 | UIGraphicsBeginImageContextWithOptions(window.bounds.size, YES, 0);
23 |
24 | // 3. 将 window 中的内容绘制输出到当前上下文
25 | [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
26 |
27 | // 4. 获取图片
28 | UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
29 |
30 | // 5. 关闭上下文
31 | UIGraphicsEndImageContext();
32 |
33 | return screenShot;
34 | }
35 |
36 | + (UIImage *)yw_blurImage:(UIImage *)image blur:(CGFloat)blur {
37 | // 模糊度越界
38 | if (blur < 0.f || blur > 1.f) {
39 | blur = 0.5f;
40 | }
41 | int boxSize = (int)(blur * 40);
42 | boxSize = boxSize - (boxSize % 2) + 1;
43 | CGImageRef img = image.CGImage;
44 | vImage_Buffer inBuffer, outBuffer;
45 | vImage_Error error;
46 | void *pixelBuffer;
47 | //从CGImage中获取数据
48 | CGDataProviderRef inProvider = CGImageGetDataProvider(img);
49 | CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
50 | //设置从CGImage获取对象的属性
51 | inBuffer.width = CGImageGetWidth(img);
52 | inBuffer.height = CGImageGetHeight(img);
53 | inBuffer.rowBytes = CGImageGetBytesPerRow(img);
54 |
55 | inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);
56 |
57 | pixelBuffer = malloc(CGImageGetBytesPerRow(img) *
58 | CGImageGetHeight(img));
59 |
60 | if(pixelBuffer == NULL){
61 | NSLog(@"No pixelbuffer");
62 | }
63 |
64 | outBuffer.data = pixelBuffer;
65 | outBuffer.width = CGImageGetWidth(img);
66 | outBuffer.height = CGImageGetHeight(img);
67 | outBuffer.rowBytes = CGImageGetBytesPerRow(img);
68 |
69 | error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend);
70 |
71 | if (error) {
72 | NSLog(@"error from convolution %ld", error);
73 | }
74 |
75 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
76 | CGContextRef ctx = CGBitmapContextCreate(
77 | outBuffer.data,
78 | outBuffer.width,
79 | outBuffer.height,
80 | 8,
81 | outBuffer.rowBytes,
82 | colorSpace,
83 | kCGImageAlphaNoneSkipLast);
84 | CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
85 | UIImage *returnImage = [UIImage imageWithCGImage:imageRef];
86 |
87 | CGContextRelease(ctx);
88 | CGColorSpaceRelease(colorSpace);
89 |
90 | free(pixelBuffer);
91 | CFRelease(inBitmapData);
92 |
93 | CGColorSpaceRelease(colorSpace);
94 | CGImageRelease(imageRef);
95 |
96 | return returnImage;
97 |
98 | }
99 |
100 | + (UIImage *)getImageOnBundle:(NSString *)imageName
101 | ofType:(NSString *)type
102 | forClass:(Class)calss{
103 |
104 | NSBundle *bundle = [NSBundle bundleForClass:calss];
105 | NSURL *url = [bundle URLForResource:@"YWAlertView" withExtension:@"bundle"];
106 | NSBundle *plistBundle = [NSBundle bundleWithURL:url];
107 | NSString *filePath = [plistBundle pathForResource:imageName ofType:type];
108 | return [UIImage imageWithContentsOfFile:filePath];
109 | }
110 |
111 | @end
112 |
--------------------------------------------------------------------------------
/YWAlertView/YWAlertView.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlertView.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/28.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YWAlertViewProtocol.h"
11 | #import "YWAddressModel.h"
12 | #import "YWSingleGeneralModel.h"
13 |
14 | typedef NS_ENUM(NSInteger, YWAlertViewStyle){
15 | YWAlertViewStyleAlert = 0,
16 | YWAlertViewStyleActionSheet = 1,
17 | YWAlertViewStyleDatePicker = 2,//datePicker默认在中间显示
18 | YWAlertViewStyleDatePicker2 = 3,//datePicke显示在底部
19 | YWAlertViewStyleAddressPicker = 4,
20 | YWAlertViewStyleSingleGeneralPicker = 5,
21 |
22 | };
23 |
24 | @interface YWAlertView : NSObject
25 |
26 | /**
27 | 创建并弹出使用代理监听点击事件的
28 |
29 | @param title 标题
30 | @param message 提示内容
31 | @param delegate 委托代理
32 | @param preferredStyle 弹框的样式
33 | @param footStyle footView的样式
34 | @param bodyStyle messageView的样式
35 | @param cancelButtonTitle 取消按钮的标题
36 | @param otherButtonTitles 其他按钮的标题
37 | @return 弹框的对象
38 | */
39 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
40 | message:(nullable NSString *)message
41 | delegate:(nullable id)delegate
42 | preferredStyle:(YWAlertViewStyle)preferredStyle
43 | footStyle:(YWAlertPublicFootStyle)footStyle
44 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
45 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
46 | otherButtonTitles:(nullable NSArray *)otherButtonTitles;
47 |
48 | /**
49 | 创建并弹出使用block监听点击事件的
50 |
51 | @param title 标题
52 | @param message 提示内容
53 | @param preferredStyle 弹框的样式
54 | @param footStyle footView的样式
55 | @param bodyStyle messageView的样式
56 | @param cancelButtonTitle 取消按钮的标题
57 | @param otherButtonTitles 其他按钮的标题
58 | @param handler blcok
59 | @return 弹框的对象
60 | */
61 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
62 | message:(nullable NSString *)message
63 | preferredStyle:(YWAlertViewStyle)preferredStyle
64 | footStyle:(YWAlertPublicFootStyle)footStyle
65 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
66 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
67 | otherButtonTitles:(nullable NSArray *)otherButtonTitles handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler;
68 |
69 | /**
70 | 快速调用datePicker使用block回调
71 |
72 | @param title 标题(可选)
73 | @param preferredStyle dataPicker的显示位置,默认YWAlertViewStyleDatePicker(中间)
74 | @param footStyle footView的样式
75 | @param bodyStyle 日历格式的样式
76 | @param cancelButtonTitle 取消按钮的标题
77 | @param sureButtonTitles 其他按钮的标题
78 | @param handler blcok
79 | @return 弹框的对象
80 | */
81 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
82 | preferredStyle:(YWAlertViewStyle)preferredStyle
83 | footStyle:(YWAlertPublicFootStyle)footStyle
84 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
85 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
86 | sureButtonTitles:(nullable NSString *)sureButtonTitles handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler;
87 |
88 | /**
89 | 快速调用signleGeneral使用blcok回调
90 |
91 | @param title 标题(可选)
92 | @param dataSource 数据源
93 | @param cancelButtonTitle 取消按钮的标题
94 | @param sureButtonTitles 其他按钮的标题
95 | @param handler blcok
96 | @return 弹框的对象
97 | */
98 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
99 | dataSource:(NSArray *_Nonnull)dataSource
100 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
101 | sureButtonTitles:(nullable NSString *)sureButtonTitles handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler;
102 |
103 |
104 |
105 |
106 | /**
107 | 快速调用signleGeneral使用delegate回调
108 |
109 | @param title 标题(可选)
110 | @param delegate 委托代理
111 | @param dataSource 数据源
112 | @param cancelButtonTitle 取消按钮的标题
113 | @param sureButtonTitles 其他按钮的标题
114 | @return 弹框的对象
115 | */
116 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
117 | delegate:(nullable id)delegate
118 | dataSource:(NSArray *_Nonnull)dataSource
119 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
120 | sureButtonTitles:(nullable NSString *)sureButtonTitles;
121 |
122 | /**
123 | 当前版本号
124 |
125 | @return 版本号
126 | */
127 | + (NSString *_Nonnull)version;
128 | @end
129 |
--------------------------------------------------------------------------------
/YWAlertView.podspec:
--------------------------------------------------------------------------------
1 | #
2 | # Be sure to run `pod spec lint YWAlertView.podspec' to ensure this is a
3 | # valid spec and to remove all comments including this before submitting the spec.
4 | #
5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7 | #
8 |
9 | Pod::Spec.new do |s|
10 |
11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12 | #
13 | # These will help people to find your library, and whilst it
14 | # can feel like a chore to fill in it's definitely to your advantage. The
15 | # summary should be tweet-length, and the description more in depth.
16 | #
17 |
18 | s.name = "YWAlertView"
19 | s.version = "1.3.6"
20 | s.summary = "弹出框"
21 |
22 | # This description is used to generate tags and improve search results.
23 | # * Think: What does it do? Why did you write it? What is the focus?
24 | # * Try to keep it short, snappy and to the point.
25 | # * Write the description between the DESC delimiters below.
26 | # * Finally, don't worry about the indent, CocoaPods strips it!
27 | s.description = "提示弹出框、选择弹出框、日期选择器、地址选择器、高效调用、高效扩展"
28 |
29 | s.homepage = "https://github.com/flyOfYW/YWAlertView"
30 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
31 |
32 |
33 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
34 | #
35 | # Licensing your code is important. See http://choosealicense.com for more info.
36 | # CocoaPods will detect a license file if there is a named LICENSE*
37 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
38 | #
39 |
40 | s.license = "MIT"
41 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" }
42 |
43 |
44 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
45 | #
46 | # Specify the authors of the library, with email addresses. Email addresses
47 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
48 | # accepts just a name if you'd rather not provide an email address.
49 | #
50 | # Specify a social_media_url where others can refer to, for example a twitter
51 | # profile URL.
52 | #
53 |
54 | s.author = { "flyOfYW" => "1498627884@qq.com" }
55 | # Or just: s.author = "flyOfYW"
56 | # s.authors = { "flyOfYW" => "1498627884@qq.com" }
57 | # s.social_media_url = "http://twitter.com/flyOfYW"
58 |
59 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
60 | #
61 | # If this Pod runs only on iOS or OS X, then specify the platform and
62 | # the deployment target. You can optionally include the target after the platform.
63 | #
64 |
65 | # s.platform = :ios
66 | s.platform = :ios, "7.0"
67 |
68 | # When using multiple platforms
69 | # s.ios.deployment_target = "5.0"
70 | # s.osx.deployment_target = "10.7"
71 | # s.watchos.deployment_target = "2.0"
72 | # s.tvos.deployment_target = "9.0"
73 |
74 |
75 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
76 | #
77 | # Specify the location from where the source should be retrieved.
78 | # Supports git, hg, bzr, svn and HTTP.
79 | #
80 |
81 | s.source = { :git => "https://github.com/flyOfYW/YWAlertView.git", :tag => s.version }
82 |
83 |
84 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
85 | #
86 | # CocoaPods is smart about how it includes source code. For source files
87 | # giving a folder will include any swift, h, m, mm, c & cpp files.
88 | # For header files it will include any header in the folder.
89 | # Not including the public_header_files will make all headers public.
90 | #
91 |
92 | s.source_files = 'YWAlertView/*'
93 | # s.exclude_files = "Classes/Exclude"
94 |
95 | # s.public_header_files = "Classes/**/*.h"
96 |
97 |
98 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
99 | #
100 | # A list of resources included with the Pod. These are copied into the
101 | # target bundle with a build phase script. Anything else will be cleaned.
102 | # You can preserve files from being cleaned, please don't preserve
103 | # non-essential files like tests, examples and documentation.
104 | #
105 |
106 | # s.resource = "icon.png"
107 | # s.resources = "Resources/*.png"
108 | s.resources = 'YWAlertView/YWAlertView.bundle'
109 |
110 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
111 |
112 |
113 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
114 | #
115 | # Link your library with frameworks, or libraries. Libraries do not include
116 | # the lib prefix of their name.
117 | #
118 |
119 | # s.framework = "SomeFramework"
120 | # s.frameworks = "SomeFramework", "AnotherFramework"
121 |
122 | # s.library = "iconv"
123 | # s.libraries = "iconv", "xml2"
124 |
125 |
126 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
127 | #
128 | # If your library depends on compiler flags you can set them in the xcconfig hash
129 | # where they will only apply to your library. If you depend on other Podspecs
130 | # you can include multiple dependencies to ensure it works.
131 |
132 | s.requires_arc = true
133 |
134 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
135 | # s.dependency "JSONKit", "~> 1.4"
136 |
137 | end
138 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YWAlertView
2 | 提示弹出框、选择弹出框、日期选择器、地址选择器、高效调用、高效扩展
3 |
4 | * 最新更新记录
5 | ```
6 | v1.3.0 YWAlertView中的YWAlertViewStyleActionSheet模式支持懒加载,支持动态修改title和message,高度自动变化
7 | v1.2.2 YWAlertView中的YWAlertViewStyleAlert模式支持懒加载,支持动态修改title和message,高度自动变化
8 | v1.2.1 新增地址选择器
9 | v1.0.0 新增日历选择器以及时间格式化以及时间戳相关工具类
10 | v0.1.0 新增弹框提示和弹框选择器
11 | ```
12 | ### 兼容性
13 | * iPhone和iPad
14 | * 横屏和竖屏
15 | * iOS 7以上
16 |
17 | ### 集成方法
18 | 1. 将YWAlertView文件拖入项目,引入头文件
19 | > #import "YWAlertView.h"
20 | 2. 使用cocopod
21 | ```ruby
22 | pod 'YWAlertView'
23 | ```
24 |
25 | ### 介绍
26 |
27 | YWAlertView目前提供五种模式:
28 |
29 | > YWAlertViewStyleAlert
30 | > YWAlertViewStyleActionSheet
31 | > YWAlertViewStyleDatePicker ////datePicker默认在中间显示
32 | > YWAlertViewStyleDatePicker2 //datePicker底部显示
33 | > YWAlertViewStyleAddressPicker
34 |
35 |
36 |
37 | * 注意点:YWAlertView并不是view,可以比作是一个简单的工厂,通过它管理规格去生成不同的控件,因为这样后期将陆续加入其它的控件,日历,地址等
38 |
39 |
40 | > ##### * YWAlertViewStyleAlert 的模式
41 |
42 | > 1. 默认情况下
43 | > > 
44 | > 2. footView上的按钮横排,这个类似系统的,当多个按钮的时候,就横排显示,而YWAlertView提供三个模式:横排和竖排以及有按钮之间有间距的横排,供开发者自由选择
45 | > >  
46 | > 3. 没有footView的情况下(支持没有title和message的情况),可以选择行,把close按钮显示,字体也可以修改
47 | > > 
48 | > 4. bodyView支持自定义(默认显示文字)
49 | > > 
50 | > 5. 全局配置基本设置(色调、背景、字体大小、字号等)解决在每次弹框设置这些的参数的烦恼
51 | > > 
52 | > 6. 其他情况,请结合demo
53 |
54 |
55 |
56 | > ##### * YWAlertViewStyleActionSheet 的模式
57 |
58 | > 1. 默认情况下,跟系统的ActionSheet没有什么差异
59 | > > 
60 | > 2. 没有title的情况,(支持字号以及字体等修改)
61 | > > 
62 | > 3. 没有cancel的情况下
63 | > > 
64 | > 4. 其他情况,请结合demo
65 |
66 | > ##### * YWAlertViewStyleDatePicker 的模式
67 | > 1. 年月日时分秒,位置显示在中间,按钮横排显示
68 | > > 
69 | > 2. 年月日时分,位置显示在中间,按钮竖排显示
70 | > > 
71 | > 3. 年月日,位置显示在底部
72 | > > 
73 | > 4. 其他情况,请结合demo
74 |
75 | > ##### * YWAlertViewStyleAddressPicker 的模式
76 | > 1. 省市区显示
77 | > > 
78 | > 2. 省市显示
79 | > > 
80 | > 3. 其他情况,请结合demo
81 |
82 |
83 | ### 使用
84 |
85 | > 1. delegate回调
86 |
87 | ```
88 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
89 | [alert show];
90 | ```
91 |
92 | > 2. block回调
93 |
94 | ```
95 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view,typically from a nib" preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:nil otherButtonTitles:nil handler:^(NSInteger buttonIndex, id _Nullable value) {
96 | NSLog(@"block=当前点击--%zi",buttonIndex);
97 | }];
98 | [alert setMessageFontWithName:@"Bodoni Ornaments" size:15];
99 | [alert show];
100 | ```
101 |
102 | > 3. 全局配置基本参数
103 | > > 创建一个继承NSObject的实体类,并且准守协议,实现其基本的参数配置方法,在显示alert的时候使用该实体类的对象,如:
104 |
105 | ```
106 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"主题配置颜色以及背景图" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
107 | [alert setTheme:[YWTheme new]];
108 | [alert showOnViewController];
109 | ```
110 | > > 该继承NSObject的实体类的m文件内容如下,按需实现相应的方法
111 | ```
112 | @implementation YWTheme
113 | - (UIColor *)alertCancelColor{
114 | return [UIColor redColor];
115 | }
116 | - (UIImage *)alertBackgroundView{
117 | return [UIImage imageNamed:@"105459445"];
118 | }
119 | - (CGFloat)alterBackgroundViewArticulation{
120 | return 0.5;
121 | }
122 | - (NSString *)alertMessageFontWithName{
123 | return @"AmericanTypewriter";
124 | }
125 | - (NSString *)alertTitleFontWithName{
126 | return @"Baskerville-SemiBoldItalic";
127 | }
128 | @end
129 |
130 | ```
131 |
132 | > 4. 懒加载
133 |
134 | ````
135 | - (id)ywAlert{
136 | if (!_ywAlert) {
137 | _ywAlert = [YWAlertView alertViewWithTitle:nil message:@"懒加载模式,我要重置message的信息,高度也要进行相关的变化哦" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
138 | }
139 | return _ywAlert;
140 | }
141 | - (void)alert_defalut_lazing{
142 | //强转协议,调用私有方法 message 和title均支持修改
143 | [(id)self.ywAlert resetAlertMessage:@"懒加载模式,我要重置message的信息,高度也要进行相关的变化哦"];
144 | [(id)self.ywAlert resetAlertTitle:@"使用第一行的对象alter"];
145 | [self.ywAlert show];
146 | }
147 | ```
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/YWAlertView/YWAlertViewProtocol.h:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlertViewProtocol.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/28.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @class YWResultModel;
13 | @class YWSingleGeneralModel;
14 |
15 | typedef enum : NSUInteger {
16 | YWAlertPublicFootStyleDefalut,//横排
17 | YWAlertPublicFootStyleVertical,//竖排
18 | YWAlertPublicFootStyleSegmentation,//横排,按钮之间有间隔10
19 | } YWAlertPublicFootStyle;
20 |
21 | typedef enum : NSUInteger {
22 |
23 | YWAlertPublicBodyStyleDefalut,
24 | YWAlertPublicBodyStyleCustom,
25 |
26 |
27 | //YWDatePicker专用
28 | YWAlertStyleShowYearMonthDayHourMinuteSecond,//年月日时分秒
29 | YWAlertStyleShowYearMonthDayHourMinute,//年月日时分
30 | YWAlertStyleShowYearMonthDay,//年月日
31 | YWAlertStyleShowYearMonth,//年月
32 | YWAlertStyleShowHourMinuteSecond,//时分秒
33 |
34 | //YWAddressPicker专用
35 | YWAlertAddressPickerShowProvince, // 只显示省
36 | YWAlertAddressPickerShowCity,// 显示省市
37 | YWAlertAddressPickerShowArea,// 显示省市区(默认)
38 |
39 | } YWAlertPublicBodyStyle;
40 |
41 |
42 | @protocol YWAlertViewThemeProtocol
43 | @optional
44 |
45 | /**
46 | alert背景图
47 |
48 | @return im
49 | */
50 | - (UIImage *)alertBackgroundView;
51 | /**
52 | alert背景图的清晰度
53 |
54 | @return 0~1(越小越清晰)
55 | */
56 | - (CGFloat)alterBackgroundViewArticulation;
57 |
58 | /**
59 | alert的背景颜色
60 |
61 | @return color
62 | */
63 | - (UIColor *)alertBackgroundColor;
64 | /**
65 | titleView的颜色
66 |
67 | @return color
68 | */
69 | - (UIColor *)alertTitleViewColor;
70 | /**
71 | 取消按钮的颜色
72 |
73 | @return color
74 | */
75 | - (UIColor *)alertCancelColor;
76 | /**
77 | 修改title的字体
78 |
79 | @return string
80 | */
81 | - (NSString *)alertTitleFontWithName;
82 | /**
83 | 修改title的字号大小
84 |
85 | @return string
86 | */
87 | - (CGFloat )alertTitleFont;
88 | /**
89 | 修改Message的字体
90 |
91 | @return string
92 | */
93 | - (NSString *)alertMessageFontWithName;
94 | /**
95 | 修改title的字号大小
96 |
97 | @return string
98 | */
99 | - (CGFloat )alertMessageFont;
100 |
101 | @end
102 |
103 | //MARK: --------- YWAlertViewProtocol(基本接口协议)
104 | @protocol YWAlertViewProtocol
105 | @required
106 | /**
107 | 默认显示在Windows上
108 | */
109 | - (void)show;
110 | /**
111 | 配合懒加载,即时即地show的时候,回调
112 |
113 | @param handler 回调
114 | */
115 | - (void)showWindowWithHandler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler;
116 | /**
117 | 隐藏弹框
118 | */
119 | - (void)hiddenAlertView;
120 | //config配置信息
121 | @optional
122 | /**
123 | 显示在viewController上
124 | */
125 | - (void)showOnViewController;
126 | /**
127 | 隐藏bodyview上下的两个分隔线
128 | */
129 | - (void)hiddenBodyLineView;
130 | /**
131 | 隐藏所有的分隔线
132 | */
133 | - (void)hiddenAllLineView;
134 |
135 | /**
136 | 设置整个弹框的背景颜色
137 |
138 | @param color 颜色
139 | */
140 | - (void)setAlertViewBackgroundColor:(UIColor *)color;
141 | /**
142 | 设置titleView的背景颜色
143 |
144 | @param color 颜色
145 | */
146 | - (void)setTitleViewBackColor:(UIColor *)color;
147 | /**
148 | 设置titleView的title颜色
149 |
150 | @param color 颜色
151 | */
152 | - (void)setTitleViewTitleColor:(UIColor *)color;
153 | /**
154 | 设置message的字体颜色
155 |
156 | @param color 颜色
157 | */
158 | - (void)setMessageTitleColor:(UIColor *)color;
159 | /**
160 | 设置所有按钮的字体颜色
161 |
162 | @param color 颜色
163 | */
164 | - (void)setAllButtionTitleColor:(UIColor *)color;
165 | /**
166 | 设置单个按钮的颜色
167 |
168 | @param color 颜色
169 | @param index 下标
170 | */
171 | - (void)setButtionTitleColor:(UIColor *)color index:(NSInteger)index;
172 | /**
173 | 设置单个按钮的字体以及其大小
174 |
175 | @param name 什么字体
176 | @param size 大小
177 | @param index 小标
178 | */
179 | - (void)setButtionTitleFontWithName:(NSString *)name size:(CGFloat)size index:(NSInteger)index;
180 | /**
181 | 设置title的字体以及其大小
182 |
183 | @param name 什么字体(为nil时,即是系统字体)
184 | @param size 大小
185 | */
186 | - (void)setTitleFontWithName:(NSString *)name size:(CGFloat)size;
187 | /**
188 | 设置message的字体以及其大小
189 |
190 | @param name 什么字体(为nil时,即是系统字体)
191 | @param size 大小
192 | */
193 | - (void)setMessageFontWithName:(NSString *)name size:(CGFloat)size;
194 | /**
195 | 设置蒙版的背景图
196 |
197 | @param image 蒙版的背景图(可使用高斯的image)
198 | */
199 | - (void)setGaussianBlurImage:(UIImage *)image;
200 | /**
201 | 统一配置信息
202 |
203 | @param theme 主题
204 | */
205 | - (void)setTheme:(id)theme;
206 |
207 |
208 | /**
209 | 修改tiele
210 |
211 | @param title 提示名称
212 | */
213 | - (void)resetAlertTitle:(NSString *)title;
214 | @end
215 |
216 |
217 |
218 | //MARK: ------------------ addressPicker 私有的方法 ------------------
219 | @protocol YWAlertAddressPickerViewProtocol
220 | /**
221 | 设置
222 |
223 | @param defalutModel 默认的省市区(具体使用,参考demo)
224 | */
225 | - (void)setDefalutOnAddressPickerView:(YWResultModel *)defalutModel;
226 | /**
227 | 设置picker的高度
228 |
229 | @param height 高度
230 | */
231 | - (void)setPickerHeightOnAddressPickerView:(CGFloat)height;
232 | @end
233 |
234 | //MARK: ------------------ addressPicker 私有的方法 ------------------
235 | @protocol YWAlertSingleGeneralPickerViewProtocol
236 | /**
237 | 设置
238 |
239 | @param defalutModel 默认的省市区(具体使用,参考demo)
240 | */
241 | - (void)setDefalutOnSingleGeneraPickerView:(YWSingleGeneralModel *)defalutModel;
242 | /**
243 | 设置picker的高度
244 |
245 | @param height 高度
246 | */
247 | - (void)setPickerHeightOnAddressPickerView:(CGFloat)height;
248 | @end
249 |
250 |
251 |
252 | //MARK: ------------------- datePicker 私有的方法 ------------------
253 | @protocol YWAlertDatePickerViewProtocol
254 | /**
255 | 设置默认选中的时间,该方法针对日期选择模式有效
256 |
257 | @param dateString 默认选中的时间
258 | */
259 | - (void)selectedDateOnDatePickerView:(NSString *)dateString;
260 | /**
261 | 设置picker的高度
262 |
263 | @param height 高度
264 | */
265 | - (void)setPickerHeightOnDatePickerView:(CGFloat)height;
266 |
267 | @end
268 |
269 | @protocol YWAlertActionSheetViewProtocol
270 | /**
271 | 修改message信息,高度也会跟着适配
272 |
273 | @param message 信息
274 | */
275 | - (void)resetAlertMessage:(NSString *)message;
276 |
277 | @end
278 |
279 | //MARK: ------------------ alert 私有的方法 ------------------
280 | @protocol YWAlertAlertViewProtocol
281 | /**
282 | alert背景图(目前对YWAlert有效)
283 |
284 | @param image image
285 | @param articulation 0~1(越小越清晰)
286 | */
287 | - (void)setAlertBackgroundView:(UIImage *)image articulation:(CGFloat)articulation;
288 | /**
289 | 自定义bodyview
290 |
291 | @param bodyView 需要定义的view
292 | @param height 该view的高度
293 | */
294 | - (void)setCustomBodyView:(UIView *)bodyView height:(CGFloat)height;
295 | /**
296 | 是否显示关闭的按妞
297 | */
298 | - (void)showCloseOnTitleView;
299 | /**
300 | 修改message信息,高度也会跟着适配
301 |
302 | @param message 信息
303 | */
304 | - (void)resetAlertMessage:(NSString *)message;
305 |
306 | @end
307 |
308 |
309 |
310 |
311 | @protocol YWAlertViewDelegate
312 |
313 | @optional
314 | /**
315 | 点击view的回调
316 |
317 | @param buttonIndex 点击的下标
318 | @param value 标题名称
319 | */
320 | - (void)didClickAlertView:(NSInteger)buttonIndex value:(id)value;
321 | @end
322 |
323 |
324 |
325 |
--------------------------------------------------------------------------------
/YWAlertView/NSDate+YW.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSDate+YW.h
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/9/17.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | static NSString* const YW_DEFAULT_FORMAT = @"yyyy-MM-dd";
12 | static NSString* const YW_YYYYMM = @"yyyy-MM";
13 | static NSString* const YW_YYYYMMDDHHMM = @"yyyy-MM-dd HH:mm";
14 | static NSString* const YW_YYYYMMDDHHMMSS = @"yyyy-MM-dd HH:mm:ss";
15 | static NSString* const YW_HHMMSS = @"HH:mm:ss";
16 | static NSString* const YW_HHMM = @"HH:mm";
17 |
18 | typedef enum : NSUInteger {
19 | YWDateStyleYYYYMMDD,//yyyy-MM-dd
20 | YWDateStyleYYYYMM,//yyyy-MM
21 | YWDateStyleYYYYMMDDHHMM,//yyyy-MM-dd HH:mm
22 | YWDateStyleYYYYMMDDHHMMSS,//yyyy-MM-dd HH:mm:ss
23 | YWDateStyleHHMMSS,//HH:mm:ss
24 | YWDateStyleHHMM,//HH:mm
25 | } YWDateStyle;
26 |
27 |
28 | @interface NSDate (YW)
29 | //获取该NSDate的年份
30 | @property (readonly) NSInteger year;
31 | //获取该NSDate的月份
32 | @property (readonly) NSInteger month;
33 | //获取该NSDate的号数
34 | @property (readonly) NSInteger day;
35 | //获取该NSDate的小时
36 | @property (readonly) NSInteger hour;
37 | //获取该NSDate的分钟
38 | @property (readonly) NSInteger minute;
39 | //获取该NSDate的秒数
40 | @property (readonly) NSInteger seconds;
41 | //获取该NSDate的这个日期对应的月份共有多少天
42 | @property (readonly) NSInteger days;
43 |
44 | /**
45 | 获取NSCalendar对象
46 |
47 | @return NSCalendar
48 | */
49 | + (NSCalendar *) currentCalendar;
50 | /**
51 | 获取NSDateFormatter对象
52 |
53 | @return NSDateFormatter
54 | */
55 | + (NSDateFormatter *)currentDateFormatter;
56 | /**
57 | 将时间字符串格式成NSDate对象
58 |
59 | @param dateString 时间字符串
60 | @param dateStyle 格式模式
61 | @return NSDate
62 | */
63 | + (NSDate *)date:(NSString *)dateString format:(YWDateStyle)dateStyle;
64 |
65 | /// 两个日期比较【YYYY-MM-dd】,比较的结果等于result则不满足,否则满足
66 | /// @param fromDateStr 日期
67 | /// @param toDateStr 被比较的日期
68 | /// @param result 比较条件
69 | + (BOOL)isMeet:(NSString *)fromDateStr
70 | to:(NSString *)toDateStr
71 | compare:(NSComparisonResult)result;
72 |
73 | /// 两个日期比较【YYYY-MM】,比较的结果等于result则不满足,否则满足
74 | /// @param fromDateStr 日期
75 | /// @param toDateStr 被比较的日期
76 | /// @param result 比较条件
77 | + (BOOL)isMeetOnYYYYMM:(NSString *)fromDateStr
78 | to:(NSString *)toDateStr
79 | compare:(NSComparisonResult)result;
80 | /**
81 | 将时间戳转时间格式的日期字符串
82 |
83 | @param timeStamp 时间戳
84 | @param dateStyle 需要转化的格式
85 | @return 日期字符串
86 | */
87 | + (NSString *)dateByTimeStamp:(long long)timeStamp format:(YWDateStyle)dateStyle;
88 |
89 | /**
90 | 将时间戳转时间格式的日期字符串(yyyy-MMM-dd HH:mm:ss)[不使用通过NSDateFormatter对象进行转换,而是通过C语言转换,效率更高]
91 |
92 | @param timeStamp 时间戳
93 | @return 日期字符串(yyyy-MMM-dd HH:mm:ss)
94 | */
95 | + (NSString *)dateYYYYMMDDHHMMSSByTimeStamp:(long long)timeStamp;
96 | /**
97 | 将时间戳转时间格式的日期字符串(yyyy-MMM-dd HH:mm)[不使用通过NSDateFormatter对象进行转换,而是通过C语言转换,效率更高]
98 |
99 | @param timeStamp 时间戳
100 | @return 日期字符串(yyyy-MMM-dd HH:mm)
101 | */
102 | + (NSString *)dateYYYYMMDDHHMMByTimeStamp:(long long)timeStamp;
103 | /**
104 | 将时间戳转时间格式的日期字符串(yyyy-MMM-dd)[不使用通过NSDateFormatter对象进行转换,而是通过C语言转换,效率更高]
105 |
106 | @param timeStamp 时间戳
107 | @return 日期字符串(yyyy-MMM-dd)
108 | */
109 | + (NSString *)dateYYYYMMDDByTimeStamp:(long long)timeStamp;
110 | /**
111 | 将时间戳转时间格式的日期字符串(yyyy-MMM)[不使用通过NSDateFormatter对象进行转换,而是通过C语言转换,效率更高]
112 |
113 | @param timeStamp 时间戳
114 | @return 日期字符串(yyyy-MMM)
115 | */
116 | + (NSString *)dateYYYYMMByTimeStamp:(long long)timeStamp;
117 | /**
118 | 将时间戳转时间格式的日期字符串(HH:mm:ss)[不使用通过NSDateFormatter对象进行转换,而是通过C语言转换,效率更高]
119 |
120 | @param timeStamp 时间戳
121 | @return 日期字符串(HH:mm:ss)
122 | */
123 | + (NSString *)dateHHMMSSByTimeStamp:(long long)timeStamp;
124 | /**
125 | 将时间戳转时间格式的日期字符串(HH:mm)[不使用通过NSDateFormatter对象进行转换,而是通过C语言转换,效率更高]
126 |
127 | @param timeStamp 时间戳
128 | @return 日期字符串(HH:mm)
129 | */
130 | + (NSString *)dateHHMMByTimeStamp:(long long)timeStamp;
131 |
132 | /**
133 | 获取昨天的日期
134 |
135 | @return 日期
136 | */
137 | + (NSString *)getDateOfYesterday;
138 | /**
139 | 获取当期的日期
140 |
141 | @return 日期
142 | */
143 | + (NSString *)getDateOfNow;
144 | /**
145 | 获取明天的日期
146 |
147 | @return 日期
148 | */
149 | + (NSString *)getDateOfTomorrow;
150 | /**
151 | 获取本月最后一天的日期
152 |
153 | @return 日期
154 | */
155 | + (NSString *)getDateOfThisMonth;
156 | /**
157 | 获取某天的几天前的日期
158 |
159 | @param someDate 某天(someData为nil时,默认今天)
160 | @param day 天数
161 | @return 日期
162 | */
163 | + (NSString *)getTheDateBeforeSomeday:(NSDate *)someDate
164 | day:(NSInteger)day;
165 | /**
166 | 获取某天的几天后的日期
167 |
168 | @param someDate 某天(someData为nil时,默认今天)
169 | @param day 天数
170 | @return 日期
171 | */
172 | + (NSString *)getTheDateAfterSomeday:(NSDate *)someDate
173 | day:(NSInteger)day;
174 | /**
175 | 获取本季度的第一天日期
176 |
177 | @return 日期
178 | */
179 | + (NSString *)getTheDateOfTheFirstDayOfTheQuarter;
180 | /**
181 | 获取本季度的最后一天日期
182 |
183 | @return 日期
184 | */
185 | + (NSString *)getTheDateOfTheLastDayOfTheQuarter;
186 |
187 | /**
188 | 获取昨天的起始秒(单位:秒(s))
189 |
190 | @return 昨天的起始秒
191 | */
192 | + (NSTimeInterval)getStartTimeOfYesterday;
193 | /**
194 | 获取昨天的结束秒(单位:秒(s))
195 |
196 | @return 昨天的结束秒
197 | */
198 | + (NSTimeInterval)getEndTimeOfYesterday;
199 | /**
200 | 获取当前的时间戳
201 |
202 | @return 当前的时间戳
203 | */
204 | + (NSTimeInterval)getNowTimeInterval;
205 | /**
206 | 获取今天的起始秒(单位:秒(s))
207 |
208 | @return 今天的起始秒
209 | */
210 | + (NSTimeInterval)getStartTimeOfToday;
211 | /**
212 | 获取今天的结束秒(单位:秒(s))
213 |
214 | @return 今天的结束秒
215 | */
216 | + (NSTimeInterval)getEndTimeOfToday;
217 | /**
218 | 获取该天的起始秒(单位:秒(s))
219 |
220 | @param theDate 该天的日期
221 | @return 该天的起始秒
222 | */
223 | + (NSTimeInterval)getStartTimeOfThisDay:(NSDate *)theDate;
224 | /**
225 | 获取该天的结束秒(单位:秒(s))
226 |
227 | @param theDate 该天的日期
228 | @return 该天的结束秒
229 | */
230 | + (NSTimeInterval)getEndTimeOfThisDay:(NSDate *)theDate;
231 | /**
232 | 获取上个月的起始秒(单位:秒)
233 |
234 | @return 上个月的起始秒
235 | */
236 | + (NSTimeInterval)getStartTimeOfLastMonth;
237 | /**
238 | 获取上个月的结束秒(单位:秒)
239 |
240 | @return 上个月的结束秒
241 | */
242 | + (NSTimeInterval)getEndTimeOfLastMonth;
243 | /**
244 | 获取该月的起始秒 (单位:秒)
245 |
246 | @param date 日期(支持yyyy-MM yyyy-MM-dd等格式)
247 | @return 该月的起始秒
248 | */
249 | + (NSTimeInterval)getStartTimeOfTheMonth:(NSDate *)date;
250 | /**
251 | 该月的结束秒 (单位:秒)
252 |
253 | @param date 日期(支持yyyy-MM yyyy-MM-dd等格式)
254 | @return 该月的结束秒
255 | */
256 | + (NSTimeInterval)getEndTimeOfTheMonth:(NSDate*)date;
257 | /**
258 | 获取本月的起始秒(单位:秒)
259 |
260 | @return 本月的起始秒
261 | */
262 | + (NSTimeInterval)getStartTimeOfThisMonth;
263 | /**
264 | 获取本月的起始秒(单位:秒)
265 |
266 | @return 本月的起始秒
267 | */
268 | + (NSTimeInterval)getEndTimeOfThisMonth;
269 | /**
270 | 获取本季度的开始秒 (单位:秒)
271 |
272 | * @return: 本季的开始秒
273 | */
274 | + (NSTimeInterval)getStartTimeOfThisSeason;
275 |
276 | /**
277 | 获取本季度的结束秒 (单位:秒)
278 |
279 | * @return: 本季的结束秒
280 | */
281 | + (NSTimeInterval) getEndTimeOfThisSeason;
282 | /**
283 | 获取本年的起始秒
284 |
285 | @return 本年的起始秒
286 | */
287 | + (NSTimeInterval)getStartTimeOfThisYear;
288 | /**
289 | 获取本年的结束秒
290 |
291 | @return 本年的结束秒
292 | */
293 | + (NSTimeInterval)getEndTimeOfThisYear;
294 | /**
295 | 获取上年的起始秒
296 |
297 | @return 上年的起始秒
298 | */
299 | + (NSTimeInterval) getStartTimeOfLastYear;
300 | /**
301 | 获取上年的结束秒
302 |
303 | @return 上年的结束秒
304 | */
305 | + (NSTimeInterval) getEndTimeOfLastYear;
306 | @end
307 |
--------------------------------------------------------------------------------
/YWAlertView/YWAlertView.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWAlertView.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/28.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWAlertView.h"
10 | #import "YWAlert.h"
11 | #import "YWActionSheet.h"
12 | #import "YWDatePicker.h"
13 | #import "YWAddressPicker.h"
14 | #import "YWSingleGeneralPicker.h"
15 |
16 | @implementation YWAlertView
17 |
18 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
19 | message:(nullable NSString *)message
20 | delegate:(nullable id)delegate
21 | preferredStyle:(YWAlertViewStyle)preferredStyle
22 | footStyle:(YWAlertPublicFootStyle)footStyle
23 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
24 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
25 | otherButtonTitles:(nullable NSArray *)otherButtonTitles{
26 | idalertView = nil;
27 | switch (preferredStyle) {
28 | case YWAlertViewStyleAlert:
29 | alertView = [YWAlertView YWAlertTitle:title message:message delegate:delegate footStyle:footStyle bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:nil];
30 | break;
31 | case YWAlertViewStyleActionSheet:
32 | alertView = [YWAlertView YWSheetTitle:title message:message delegate:delegate footStyle:footStyle bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:nil];
33 | break;
34 | case YWAlertViewStyleDatePicker:
35 | @throw [NSException exceptionWithName:@"调用提示" reason:@"请使用dataPicker快速调用方法" userInfo:nil];
36 | break;
37 | case YWAlertViewStyleDatePicker2:
38 | @throw [NSException exceptionWithName:@"调用提示" reason:@"请使用dataPicker快速调用方法" userInfo:nil];
39 | break;
40 |
41 | case YWAlertViewStyleAddressPicker:
42 | alertView = [YWAlertView YWAddressTitle:title message:nil delegate:delegate bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:nil];
43 | break;
44 |
45 | default:
46 | break;
47 | }
48 | return alertView;
49 | }
50 |
51 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
52 | message:(nullable NSString *)message
53 | preferredStyle:(YWAlertViewStyle)preferredStyle
54 | footStyle:(YWAlertPublicFootStyle)footStyle
55 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
56 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
57 | otherButtonTitles:(nullable NSArray *)otherButtonTitles handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
58 |
59 | idalertView = nil;
60 |
61 | switch (preferredStyle) {
62 | case YWAlertViewStyleAlert:
63 | alertView = [YWAlertView YWAlertTitle:title message:message delegate:nil footStyle:footStyle bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:handler];
64 | break;
65 | case YWAlertViewStyleActionSheet:
66 | alertView = [YWAlertView YWSheetTitle:title message:message delegate:nil footStyle:footStyle bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:handler];
67 | break;
68 | case YWAlertViewStyleDatePicker:
69 | @throw [NSException exceptionWithName:@"调用提示" reason:@"请使用dataPicker快速调用方法" userInfo:nil];
70 | break;
71 | case YWAlertViewStyleDatePicker2:
72 | @throw [NSException exceptionWithName:@"调用提示" reason:@"请使用dataPicker快速调用方法" userInfo:nil];
73 | break;
74 | case YWAlertViewStyleAddressPicker:
75 | alertView = [YWAlertView YWAddressTitle:title message:nil delegate:nil bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:handler];
76 | break;
77 | default:
78 | break;
79 | }
80 | return alertView;
81 | }
82 | //MARK: --- YWAlertViewStyleAddressPicker
83 | + (nullable id)YWAddressTitle:(nullable NSString *)title
84 | message:(nullable NSString *)message
85 | delegate:(nullable id)delegate
86 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
87 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
88 | otherButtonTitles:(nullable NSArray *)otherButtonTitles
89 | handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
90 |
91 | return [[YWAddressPicker alloc] initWithTitle:title delegate:delegate bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle okButtonTitles:otherButtonTitles.firstObject handler:handler];
92 | }
93 |
94 |
95 | //MARK: --- YWAlertViewStyleActionSheet
96 | + (nullable id)YWSheetTitle:(nullable NSString *)title
97 | message:(nullable NSString *)message
98 | delegate:(nullable id)delegate
99 | footStyle:(YWAlertPublicFootStyle)footStyle
100 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
101 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
102 | otherButtonTitles:(nullable NSArray *)otherButtonTitles
103 | handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
104 | return [[YWActionSheet alloc] initWithTitle:title message:message delegate:delegate footStyle:footStyle bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:handler];
105 | }
106 |
107 |
108 |
109 | //MARK: --- YWAlertViewStyleAlert
110 | + (nullable id)YWAlertTitle:(nullable NSString *)title
111 | message:(nullable NSString *)message
112 | delegate:(nullable id)delegate
113 | footStyle:(YWAlertPublicFootStyle)footStyle
114 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
115 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
116 | otherButtonTitles:(nullable NSArray *)otherButtonTitles
117 | handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
118 |
119 | return [[YWAlert alloc] initWithTitle:title message:message delegate:delegate footStyle:footStyle bodyStyle:bodyStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles handler:handler];
120 |
121 | }
122 |
123 |
124 |
125 |
126 | //MARK: --- 日期的快速调用方法
127 | + (nullable id)alertViewWithTitle:(nullable NSString *)title
128 | preferredStyle:(YWAlertViewStyle)preferredStyle
129 | footStyle:(YWAlertPublicFootStyle)footStyle
130 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
131 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
132 | sureButtonTitles:(nullable NSString *)sureButtonTitles handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
133 | if (preferredStyle == YWAlertViewStyleDatePicker) {
134 | return [[YWDatePicker alloc] initWithTitle:title delegate:nil footStyle:footStyle bodyStyle:bodyStyle mode:0 cancelButtonTitle:cancelButtonTitle okButtonTitles:sureButtonTitles handler:handler];
135 | }else if (preferredStyle == YWAlertViewStyleDatePicker2){
136 | return [[YWDatePicker alloc] initWithTitle:title delegate:nil footStyle:footStyle bodyStyle:bodyStyle mode:1 cancelButtonTitle:cancelButtonTitle okButtonTitles:sureButtonTitles handler:handler];
137 | }else{
138 | @throw [NSException exceptionWithName:@"提示" reason:@"请检查preferredStyle是否正确" userInfo:nil];
139 | return nil;
140 | }
141 | }
142 | + (nullable id)alertViewWithTitle:(nullable NSString *)title
143 | preferredStyle:(YWAlertViewStyle)preferredStyle
144 | delegate:(nullable id)delegate
145 | footStyle:(YWAlertPublicFootStyle)footStyle
146 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
147 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
148 | sureButtonTitles:(nullable NSString *)sureButtonTitles{
149 |
150 | if (preferredStyle == YWAlertViewStyleDatePicker) {
151 | return [[YWDatePicker alloc] initWithTitle:title delegate:delegate footStyle:footStyle bodyStyle:bodyStyle mode:0 cancelButtonTitle:cancelButtonTitle okButtonTitles:sureButtonTitles handler:nil];
152 | }else if (preferredStyle == YWAlertViewStyleDatePicker2){
153 | return [[YWDatePicker alloc] initWithTitle:title delegate:delegate footStyle:footStyle bodyStyle:bodyStyle mode:1 cancelButtonTitle:cancelButtonTitle okButtonTitles:sureButtonTitles handler:nil];
154 | }else{
155 | @throw [NSException exceptionWithName:@"提示" reason:@"请检查preferredStyle是否正确" userInfo:nil];
156 | return nil;
157 | }
158 |
159 | }
160 |
161 |
162 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
163 | dataSource:(NSArray *_Nonnull)dataSource
164 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
165 | sureButtonTitles:(nullable NSString *)sureButtonTitles handler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
166 |
167 | return [[YWSingleGeneralPicker alloc] initWithTitle:title delegate:nil dataSource:dataSource cancelButtonTitle:cancelButtonTitle okButtonTitles:sureButtonTitles handler:handler];
168 | }
169 |
170 |
171 |
172 | +(nullable id)alertViewWithTitle:(nullable NSString *)title
173 | delegate:(nullable id)delegate
174 | dataSource:(NSArray *_Nonnull)dataSource
175 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
176 | sureButtonTitles:(nullable NSString *)sureButtonTitles{
177 | return [[YWSingleGeneralPicker alloc] initWithTitle:title delegate:delegate dataSource:dataSource cancelButtonTitle:cancelButtonTitle okButtonTitles:sureButtonTitles handler:nil];
178 |
179 | }
180 |
181 | + (NSString *)version{
182 | return @"1.3.6";
183 | }
184 | @end
185 |
--------------------------------------------------------------------------------
/YWAlertView/NSDate+YW.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSDate+YW.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/9/17.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "NSDate+YW.h"
10 |
11 | #define YW_MONTHS_IN_A_SEASON 3 // 1季的月数
12 |
13 | static const unsigned componentFlags = (NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekOfMonth | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitWeekday | NSCalendarUnitWeekdayOrdinal);
14 |
15 |
16 | @implementation NSDate (YW)
17 |
18 | + (NSCalendar *)currentCalendar{
19 | static NSCalendar *sharedCalendar = nil;
20 | if (!sharedCalendar)
21 | sharedCalendar = [NSCalendar autoupdatingCurrentCalendar];
22 | return sharedCalendar;
23 | }
24 | + (NSDateFormatter *)currentDateFormatter{
25 | static NSDateFormatter *sharedDateFormatter = nil;
26 | if (!sharedDateFormatter) {
27 | sharedDateFormatter = [[NSDateFormatter alloc] init];
28 | }
29 | return sharedDateFormatter;
30 | }
31 |
32 | //MARK: ----------- 日期比较 ---------------------
33 |
34 | /// 两个日期比较【YYYY-MM-dd】,比较的结果等于result则不满足,否则满足
35 | /// @param fromDateStr 日期
36 | /// @param toDateStr 被比较的日期
37 | /// @param result 比较条件
38 | + (BOOL)isMeet:(NSString *)fromDateStr
39 | to:(NSString *)toDateStr
40 | compare:(NSComparisonResult)result{
41 | NSDate *date = [self date:fromDateStr format:YWDateStyleYYYYMMDD];
42 | NSDate *endDate = [self date:toDateStr format:YWDateStyleYYYYMMDD];
43 | if ([date compare:endDate] == result) {
44 | return NO;
45 | }
46 | return YES;
47 | }
48 | /// 两个日期比较【YYYY-MM】,比较的结果等于result则不满足,否则满足
49 | /// @param fromDateStr 日期
50 | /// @param toDateStr 被比较的日期
51 | /// @param result 比较条件
52 | + (BOOL)isMeetOnYYYYMM:(NSString *)fromDateStr
53 | to:(NSString *)toDateStr
54 | compare:(NSComparisonResult)result{
55 | NSDate *date = [self date:fromDateStr format:YWDateStyleYYYYMM];
56 | NSDate *endDate = [self date:toDateStr format:YWDateStyleYYYYMM];
57 | if ([date compare:endDate] == result) {
58 | return NO;
59 | }
60 | return YES;
61 | }
62 |
63 | //MARK: ----------- 将日期格式字符串转NSDate日期相关 ---------------------
64 | + (NSDate *)date:(NSString *)dateString format:(YWDateStyle)dateStyle{
65 | switch (dateStyle) {
66 | case YWDateStyleYYYYMMDDHHMMSS:
67 | return [self date:dateString formatString:@"yyyy-MM-dd HH:mm:ss"];
68 | break;
69 | case YWDateStyleYYYYMMDDHHMM:
70 | return [self date:dateString formatString:@"yyyy-MM-dd HH:mm"];
71 | break;
72 | case YWDateStyleYYYYMMDD:
73 | return [self date:dateString formatString:@"yyyy-MM-dd"];
74 | break;
75 | case YWDateStyleYYYYMM:
76 | return [self date:dateString formatString:@"yyyy-MM"];
77 | break;
78 | case YWDateStyleHHMMSS:
79 | return [self date:dateString formatString:@"HH:mm:ss"];
80 | break;
81 | case YWDateStyleHHMM:
82 | return [self date:dateString formatString:@"HH:mm:"];
83 | break;
84 | default:
85 | break;
86 | }
87 | return [NSDate date];
88 | }
89 | + (NSDate *)date:(NSString *)dateString formatString:(NSString *)format{
90 | NSDateFormatter *dateFormatter = [self currentDateFormatter];
91 | [dateFormatter setDateFormat:format];
92 | return [dateFormatter dateFromString:dateString];
93 | }
94 |
95 |
96 | //MARK: ----------- 将时间戳转日期格式字符串相关 ---------------------
97 | + (NSString *)dateByTimeStamp:(long long)timeStamp format:(YWDateStyle)dateStyle{
98 | switch (dateStyle) {
99 | case YWDateStyleYYYYMMDDHHMMSS:
100 | return [self dateYYYYMMDDHHMMSSByTimeStamp:timeStamp];
101 | break;
102 | case YWDateStyleYYYYMMDDHHMM:
103 | return [self dateYYYYMMDDHHMMByTimeStamp:timeStamp];
104 | break;
105 | case YWDateStyleYYYYMMDD:
106 | return [self dateYYYYMMDDByTimeStamp:timeStamp];
107 | break;
108 | case YWDateStyleYYYYMM:
109 | return [self dateYYYYMMByTimeStamp:timeStamp];
110 | break;
111 | case YWDateStyleHHMMSS:
112 | return [self dateHHMMSSByTimeStamp:timeStamp];
113 | break;
114 | case YWDateStyleHHMM:
115 | return [self dateHHMMByTimeStamp:timeStamp];
116 | break;
117 | default:
118 | break;
119 | }
120 | return @"";
121 | }
122 | + (NSString *)dateYYYYMMDDHHMMSSByTimeStamp:(long long)timeStamp{
123 |
124 | time_t timeInterval = [NSDate dateWithTimeIntervalSince1970:timeStamp].timeIntervalSince1970;
125 |
126 | struct tm *cTime = localtime(&timeInterval);
127 |
128 | return [NSString stringWithFormat:@"%d-%02d-%02d %02d:%02d:%02d", cTime->tm_year + 1900, cTime->tm_mon + 1, cTime->tm_mday,cTime->tm_hour,cTime->tm_min,cTime->tm_sec];
129 | }
130 | + (NSString *)dateYYYYMMDDHHMMByTimeStamp:(long long)timeStamp{
131 |
132 | time_t timeInterval = [NSDate dateWithTimeIntervalSince1970:timeStamp].timeIntervalSince1970;
133 |
134 | struct tm *cTime = localtime(&timeInterval);
135 |
136 | return [NSString stringWithFormat:@"%d-%02d-%02d %02d:%02d", cTime->tm_year + 1900, cTime->tm_mon + 1, cTime->tm_mday,cTime->tm_hour,cTime->tm_min];
137 | }
138 | + (NSString *)dateYYYYMMDDByTimeStamp:(long long)timeStamp{
139 |
140 | time_t timeInterval = [NSDate dateWithTimeIntervalSince1970:timeStamp].timeIntervalSince1970;
141 |
142 | struct tm *cTime = localtime(&timeInterval);
143 |
144 | return [NSString stringWithFormat:@"%d-%02d-%02d", cTime->tm_year + 1900, cTime->tm_mon + 1, cTime->tm_mday];
145 | }
146 | + (NSString *)dateYYYYMMByTimeStamp:(long long)timeStamp{
147 |
148 | time_t timeInterval = [NSDate dateWithTimeIntervalSince1970:timeStamp].timeIntervalSince1970;
149 |
150 | struct tm *cTime = localtime(&timeInterval);
151 |
152 | return [NSString stringWithFormat:@"%d-%02d", cTime->tm_year + 1900, cTime->tm_mon + 1];
153 | }
154 | + (NSString *)dateHHMMSSByTimeStamp:(long long)timeStamp{
155 |
156 | time_t timeInterval = [NSDate dateWithTimeIntervalSince1970:timeStamp].timeIntervalSince1970;
157 |
158 | struct tm *cTime = localtime(&timeInterval);
159 |
160 | return [NSString stringWithFormat:@"%02d:%02d:%02d",cTime->tm_hour,cTime->tm_min,cTime->tm_sec];
161 | }
162 | + (NSString *)dateHHMMByTimeStamp:(long long)timeStamp{
163 |
164 | time_t timeInterval = [NSDate dateWithTimeIntervalSince1970:timeStamp].timeIntervalSince1970;
165 |
166 | struct tm *cTime = localtime(&timeInterval);
167 |
168 | return [NSString stringWithFormat:@"%02d:%02d",cTime->tm_hour,cTime->tm_min];
169 | }
170 |
171 |
172 | /**
173 | 获取昨天的日期
174 |
175 | @return 日期
176 | */
177 | + (NSString *)getDateOfYesterday{
178 |
179 | return [self getTheDateBeforeSomeday:nil day:1];
180 | }
181 | /**
182 | 获取当期的日期
183 |
184 | @return 日期
185 | */
186 | + (NSString *)getDateOfNow{
187 |
188 | [[self currentDateFormatter] setDateFormat:@"yyyy-MM-dd"];
189 |
190 | return [[self currentDateFormatter] stringFromDate:[NSDate date]];
191 | }
192 | /**
193 | 获取明天的日期
194 |
195 | @return 日期
196 | */
197 | + (NSString *)getDateOfTomorrow{
198 |
199 | return [self getTheDateAfterSomeday:nil day:1];
200 | }
201 | /**
202 | 获取本月最后一天的日期
203 |
204 | @return 日期
205 | */
206 | + (NSString *)getDateOfThisMonth{
207 |
208 | return [self dateYYYYMMDDByTimeStamp:[self getEndTimeOfThisMonth]];
209 | }
210 |
211 | /**
212 | 获取某天的几天前的日期
213 |
214 | @param someDate 某天(someData为nil时,默认今天)
215 | @param day 天数
216 | @return 日期
217 | */
218 | + (NSString *)getTheDateBeforeSomeday:(NSDate *)someDate
219 | day:(NSInteger)day{
220 |
221 | NSTimeInterval oneDay = [self getDayTimeInterval:day] ; //1天的长度
222 |
223 | [[self currentDateFormatter] setDateFormat:@"yyyy-MM-dd"];
224 |
225 | if (someDate) {
226 |
227 | return [[self currentDateFormatter] stringFromDate:[someDate initWithTimeIntervalSinceNow:-oneDay]];
228 |
229 | }
230 |
231 | return [[self currentDateFormatter] stringFromDate:[[NSDate date] initWithTimeIntervalSinceNow:-oneDay]];
232 | }
233 |
234 | /**
235 | 获取某天的几天后的日期
236 |
237 | @param someDate 某天(someData为nil时,默认今天)
238 | @param day 天数
239 | @return 日期
240 | */
241 | + (NSString *)getTheDateAfterSomeday:(NSDate *)someDate
242 | day:(NSInteger)day{
243 |
244 | NSTimeInterval oneDay = [self getDayTimeInterval:day] ; //1天的长度
245 |
246 | [[self currentDateFormatter] setDateFormat:@"yyyy-MM-dd"];
247 |
248 | if (someDate) {
249 |
250 | return [[self currentDateFormatter] stringFromDate:[someDate initWithTimeIntervalSinceNow:oneDay]];
251 |
252 | }
253 |
254 | return [[self currentDateFormatter] stringFromDate:[[NSDate date] initWithTimeIntervalSinceNow:oneDay]];
255 | }
256 | /**
257 | 获取本季度的第一天日期
258 |
259 | @return 日期
260 | */
261 | + (NSString *)getTheDateOfTheFirstDayOfTheQuarter{
262 |
263 | return [self dateYYYYMMDDByTimeStamp:[self getStartTimeOfThisSeason]];
264 | }
265 | /**
266 | 获取本季度的最后一天日期
267 |
268 | @return 日期
269 | */
270 | + (NSString *)getTheDateOfTheLastDayOfTheQuarter{
271 |
272 | return [self dateYYYYMMDDByTimeStamp:[self getEndTimeOfThisSeason]];
273 | }
274 | //MARK: ----------- 时间戳操作相关 ---------------------
275 | /**
276 | 获取昨天的起始秒(单位:秒(s))
277 |
278 | @return 昨天的起始秒
279 | */
280 | + (NSTimeInterval)getStartTimeOfYesterday{
281 |
282 | NSDateComponents* components = [self getComponentsOfDay:nil];
283 |
284 | [components setHour:-24];
285 |
286 | NSDate *nowDate = [[self currentCalendar] dateFromComponents:components];
287 |
288 | return [nowDate timeIntervalSince1970];
289 | }
290 | /**
291 | 获取昨天的结束秒(单位:秒(s))
292 |
293 | @return 昨天的结束秒
294 | */
295 | + (NSTimeInterval)getEndTimeOfYesterday{
296 | // 减一秒
297 | return [self getStartTimeOfToday] - 1;
298 | }
299 | /**
300 | 获取当前的时间戳
301 |
302 | @return 当前的时间戳
303 | */
304 | + (NSTimeInterval)getNowTimeInterval{
305 | return [[NSDate date] timeIntervalSince1970];
306 | }
307 | /**
308 | 获取今天的起始秒(单位:秒(s))
309 |
310 | @return 今天的起始秒
311 | */
312 | + (NSTimeInterval)getStartTimeOfToday{
313 |
314 | NSDateComponents* components = [self getComponentsOfDay:nil];
315 |
316 | NSDate *nowDate = [[self currentCalendar] dateFromComponents:components];
317 |
318 | return [nowDate timeIntervalSince1970];
319 | }
320 | /**
321 | 获取今天的结束秒(单位:秒(s))
322 |
323 | @return 今天的结束秒
324 | */
325 | + (NSTimeInterval)getEndTimeOfToday{
326 |
327 | NSDateComponents* components = [self getComponentsOfDay:nil];
328 |
329 | //在今天的日期位置上,hours + 24,即是明天的起始日期,
330 | [components setHour:+24];
331 |
332 | NSDate *nowDate = [[self currentCalendar] dateFromComponents:components];
333 |
334 | // 在减去1s,就是今日的最后的秒数
335 | return [nowDate timeIntervalSince1970] - 1;
336 | }
337 | /**
338 | 获取该天的起始秒(单位:秒(s))
339 |
340 | @param theDate 该天的日期
341 | @return 该天的起始秒
342 | */
343 | + (NSTimeInterval)getStartTimeOfThisDay:(NSDate *)theDate{
344 |
345 | NSDateComponents* components = [self getComponentsOfDay:theDate];
346 |
347 | NSDate* date = [[self currentCalendar] dateFromComponents:components];
348 |
349 | return [date timeIntervalSince1970];
350 | }
351 | /**
352 | 获取该天的结束秒(单位:秒(s))
353 |
354 | @param theDate 该天的日期
355 | @return 该天的结束秒
356 | */
357 | + (NSTimeInterval)getEndTimeOfThisDay:(NSDate *)theDate{
358 |
359 | NSDateComponents* components = [self getComponentsOfDay:theDate];
360 |
361 | [components setHour: +24];
362 |
363 | NSDate* date = [[self currentCalendar] dateFromComponents:components];
364 |
365 | return [date timeIntervalSince1970]- 1;
366 | }
367 | /**
368 | 获取上个月的起始秒(单位:秒)
369 |
370 | @return 上个月的起始秒
371 | */
372 | + (NSTimeInterval)getStartTimeOfLastMonth{
373 |
374 | NSDateComponents * components = [self getComponentsOfMonth];
375 |
376 | [components setMonth: [components month] - 1];
377 |
378 | NSDate *date = [[self currentCalendar] dateFromComponents:components];
379 |
380 | return [date timeIntervalSince1970];
381 | }
382 | /**
383 | 获取上个月的结束秒(单位:秒)
384 |
385 | @return 上个月的结束秒
386 | */
387 | + (NSTimeInterval)getEndTimeOfLastMonth{
388 |
389 | //设置当前月的第一天的起始日期(精确到秒)
390 | NSDateComponents * components = [self getComponentsOfMonth];
391 |
392 | NSDate* date = [[self currentCalendar] dateFromComponents:components];
393 |
394 | // [date timeIntervalSince1970] 其实是本月的起始秒
395 | return [date timeIntervalSince1970] - 1;
396 | }
397 | /**
398 | 获取该月的起始秒 (单位:秒)
399 |
400 | @param date 日期(支持yyyy-MM yyyy-MM-dd等格式)
401 | @return 该月的起始秒
402 | */
403 | + (NSTimeInterval)getStartTimeOfTheMonth:(NSDate *)date{
404 |
405 | NSDateComponents *components = [self getComponentOfMonth: date];
406 |
407 | NSDate *newDate = [[self currentCalendar] dateFromComponents:components];
408 |
409 | return [newDate timeIntervalSince1970];
410 | }
411 |
412 | /**
413 | 该月的结束秒 (单位:秒)
414 |
415 | @param date 日期(支持yyyy-MM yyyy-MM-dd等格式)
416 | @return 该月的结束秒
417 | */
418 | + (NSTimeInterval)getEndTimeOfTheMonth:(NSDate*)date{
419 |
420 | // 该月的起始秒
421 | NSDateComponents* components = [self getComponentOfMonth:date];
422 |
423 | // 加1月
424 | [components setMonth: [components month] + 1];
425 |
426 | NSDate *newDate = [[self currentCalendar] dateFromComponents:components];
427 |
428 | return [newDate timeIntervalSince1970] - 1;
429 | }
430 | /**
431 | 获取本月的起始秒(单位:秒)
432 |
433 | @return 本月的起始秒
434 | */
435 | + (NSTimeInterval)getStartTimeOfThisMonth{
436 |
437 | return [self getStartTimeOfTheMonth:[NSDate date]];
438 | }
439 | /**
440 | 获取本月的结束秒(单位:秒)
441 |
442 | @return 本月的结束秒
443 | */
444 | + (NSTimeInterval)getEndTimeOfThisMonth{
445 |
446 | return [self getEndTimeOfTheMonth:[NSDate date]];
447 | }
448 |
449 | /**
450 | 获取本季度的开始秒 (单位:秒)
451 |
452 | * @return: 本季的开始秒
453 | */
454 | + (NSTimeInterval)getStartTimeOfThisSeason{
455 |
456 | NSDateComponents *components = [self getComponentsOfThisSeason];
457 |
458 | NSDate *date = [[self currentCalendar] dateFromComponents:components];
459 |
460 | return [date timeIntervalSince1970];
461 | }
462 |
463 | /**
464 | 获取本季度的结束秒 (单位:秒)
465 |
466 | * @return: 本季的结束秒
467 | */
468 | + (NSTimeInterval) getEndTimeOfThisSeason{
469 |
470 | NSDateComponents *components = [self getComponentsOfThisSeason];
471 |
472 | [components setMonth: [components month] + 3];
473 |
474 | NSDate *date = [[self currentCalendar] dateFromComponents:components];
475 |
476 | return [date timeIntervalSince1970] - 1;
477 | }
478 | /**
479 | 获取本年的起始秒
480 |
481 | @return 本年的起始秒
482 | */
483 | + (NSTimeInterval)getStartTimeOfThisYear{
484 |
485 | NSDateComponents *components = [self getComponentsOfYear];
486 |
487 | NSDate *date = [[self currentCalendar] dateFromComponents:components];
488 |
489 | return [date timeIntervalSince1970];
490 | }
491 |
492 |
493 | /**
494 | 获取本年的结束秒
495 |
496 | @return 本年的结束秒
497 | */
498 | + (NSTimeInterval)getEndTimeOfThisYear{
499 |
500 | NSDateComponents *components = [self getComponentsOfYear];
501 |
502 | [components setYear: [components year] + 1];
503 |
504 | NSDate *date = [[self currentCalendar] dateFromComponents:components];
505 |
506 | return [date timeIntervalSince1970] - 1;
507 | }
508 |
509 |
510 | /**
511 | 获取上年的起始秒
512 |
513 | @return 上年的起始秒
514 | */
515 | + (NSTimeInterval) getStartTimeOfLastYear{
516 |
517 | NSDateComponents *components = [self getComponentsOfYear];
518 |
519 | [components setYear: [components year] - 1];
520 |
521 | NSDate *date = [[self currentCalendar] dateFromComponents:components];
522 |
523 | return [date timeIntervalSince1970];
524 | }
525 | /**
526 | 获取上年的结束秒
527 |
528 | @return 上年的结束秒
529 | */
530 | + (NSTimeInterval) getEndTimeOfLastYear{
531 |
532 | return [self getStartTimeOfThisYear] - 1;
533 | }
534 | //MARK: ----------- 私有方法 -----------------
535 | /**
536 | 获取当年的第一天的包括“年”,“月”,“日”,“周”,“时”,“分”,“秒”的NSDateComponents
537 |
538 | @return 当年的第一天的包括“年”,“月”,“日”,“周”,“时”,“分”,“秒”的NSDateComponents
539 | */
540 | + (NSDateComponents*)getComponentsOfYear{
541 |
542 | NSDateComponents* components = [[NSDateComponents alloc] init];
543 |
544 | [components setYear: [[self getComponentsOfDay:nil] year]];
545 |
546 | [components setMonth: 1];
547 |
548 | return components;
549 | }
550 | /**
551 | 获取当季第一天的包括“年”,“月”,“日”,“周”,“时”,“分”,“秒”的NSDateComponents
552 |
553 | @return 当季第一天的包括“年”,“月”,“日”,“周”,“时”,“分”,“秒”的NSDateComponents
554 | */
555 | + (NSDateComponents*) getComponentsOfThisSeason{
556 |
557 | NSDateComponents* components = [self getComponentsOfDay: [NSDate date]];
558 |
559 | NSInteger thisMonth = [components month];
560 |
561 | NSInteger thisSeasonStartMonth;
562 |
563 | if(thisMonth % YW_MONTHS_IN_A_SEASON == 0){
564 | thisSeasonStartMonth = thisMonth - 2;
565 | }else{
566 | thisSeasonStartMonth = thisMonth - (thisMonth % YW_MONTHS_IN_A_SEASON - 1);
567 | }
568 |
569 | [components setMonth: thisSeasonStartMonth];
570 |
571 | NSDateComponents* thisSeasonStartMonthComponents = [[NSDateComponents alloc] init];
572 |
573 | [thisSeasonStartMonthComponents setYear: [components year]];
574 |
575 | [thisSeasonStartMonthComponents setMonth: [components month]];
576 |
577 | return thisSeasonStartMonthComponents;
578 | }
579 | /**
580 | 获取该月的“年”,“月”,“日”,“周”,“时”,“分”,“秒”的NSDateComponents
581 |
582 | @param date 日期
583 | @return NSDateComponents对象
584 | */
585 | + (NSDateComponents *)getComponentOfMonth:(NSDate *)date{
586 |
587 | NSDateComponents* components = [self getComponentsOfDay:date];
588 |
589 | [components setDay:1];
590 |
591 | return components;
592 | }
593 | /**
594 | 获取当月的“年”,“月”,“日”,“周”,“时”,“分”,“秒”的NSDateComponents
595 |
596 | @return NSDateComponents对象
597 | */
598 | + (NSDateComponents *)getComponentsOfMonth{
599 |
600 | NSDateComponents* components = [self getComponentsOfDay: [NSDate date]];
601 |
602 | NSDateComponents* firstDayCurrentMonth = [[NSDateComponents alloc] init];
603 |
604 | [firstDayCurrentMonth setYear: [components year]];
605 | [firstDayCurrentMonth setMonth: [components month]];
606 | [firstDayCurrentMonth setDay:1];//不存在0号
607 | [firstDayCurrentMonth setHour: 0];
608 | [firstDayCurrentMonth setMinute: 0];
609 | [firstDayCurrentMonth setSecond: 0];
610 |
611 | return firstDayCurrentMonth;
612 | }
613 | /**
614 | 获取指定日期的“年”,“月”,“日”,“周”,“时”,“分”,“秒”的NSDateComponents
615 |
616 | @param appointDate 指定的日期,当为空的时候,默认当前日期
617 | @return NSDateComponents对象
618 | */
619 | + (NSDateComponents *)getComponentsOfDay:(NSDate *)appointDate{
620 |
621 | if (appointDate == NULL || appointDate == nil){
622 | appointDate = [NSDate date];
623 | }
624 | NSDateComponents* components = [[NSDate currentCalendar] components:componentFlags fromDate:appointDate];
625 |
626 | // 0时0分0秒
627 | [components setHour: 0];
628 | [components setMinute: 0];
629 | [components setSecond: 0];
630 |
631 | return components;
632 | }
633 | /**
634 | 获取对应的秒数
635 |
636 | @param day 范围(单位:天)
637 | @return 秒数
638 | */
639 | + (NSTimeInterval)getDayTimeInterval:(NSInteger)day{
640 |
641 | return 24 * 60 * 60 * day; //1天的长度
642 | }
643 | //MARK: --------------------------- getter ---------------------
644 | - (NSInteger)year{
645 | NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
646 | return components.year;
647 | }
648 | - (NSInteger)month{
649 | NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
650 | return components.month;
651 | }
652 | - (NSInteger)day{
653 | NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
654 | return components.day;
655 | }
656 | - (NSInteger)hour{
657 | NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
658 | return components.hour;
659 | }
660 | - (NSInteger)minute{
661 | NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
662 | return components.minute;
663 | }
664 | - (NSInteger)seconds{
665 | NSDateComponents *components = [[NSDate currentCalendar] components:componentFlags fromDate:self];
666 | return components.second;
667 | }
668 | - (NSInteger)days{
669 | NSRange range = [[NSDate currentCalendar] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:self];
670 | return range.length;
671 | }
672 | @end
673 |
--------------------------------------------------------------------------------
/YWAlertView/YWSingleGeneralPicker.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWSingleGeneralPicker.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by Mr.Yao on 2020/2/23.
6 | // Copyright © 2020 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWSingleGeneralPicker.h"
10 | #import "YWAlertViewHelper.h"
11 | #import "UIView+Autolayout.h"
12 | #import "YWAddressModel.h"
13 | #import "YWContainerViewController.h"
14 | #import "YWSingleGeneralModel.h"
15 |
16 | @interface YWSingleGeneralPicker ()
17 |
18 | {
19 | YWAlertPublicBodyStyle _pickerStyle;
20 | BOOL _isSetSpeartorView;//是否设置过分割线的颜色
21 | NSInteger _font;//字体大小
22 | CGFloat _pickerHeight;
23 | CGFloat _pickerAlertViewWidth;
24 |
25 | NSLayoutConstraint *_layOnTitleViewHeight;//方便后期扩展自定义高度
26 | NSLayoutConstraint *_layPickerViewHeight;//方便后期扩展自定义高度
27 | BOOL _isSetFrame;//是否设置过frame
28 | BOOL _isModal;
29 |
30 | }
31 | //sheet的容器
32 | @property (nonatomic, strong) UIView *pickerAlertView;
33 | //蒙层
34 | @property (nonatomic, strong) UIView *maskView;
35 | //高斯模糊的背景图
36 | @property (nonatomic, strong) UIImageView *gaussianBlurOnMaskView;
37 | //标题的view
38 | @property (nonatomic, strong) UIView *titleView;
39 | //标题
40 | @property (nonatomic, strong) UILabel *titleLabel;
41 | //取消按钮
42 | @property (nonatomic, strong) UIButton *cancelBtn;
43 | //确认按钮
44 | @property (nonatomic, strong) UIButton *sureBtn;
45 | //picker容器
46 | @property (nonatomic, strong) UILabel *messageLabel;
47 | //picker
48 | @property (nonatomic, strong) UIPickerView *datePicker;
49 | //picker 字体颜色(默认黑色)
50 | @property (nonatomic,strong) UIColor *addressColor;
51 |
52 | @property (nonatomic, copy) void(^handler)(NSInteger buttonIndex,id value);
53 | /** 选中 */
54 | @property(nonatomic, strong) YWSingleGeneralModel *selectModel;
55 |
56 | @property(nonatomic, assign) NSInteger selectRow;
57 |
58 |
59 | @property (nonatomic, strong) NSMutableArray *listData;
60 |
61 |
62 |
63 |
64 | @end
65 |
66 | @implementation YWSingleGeneralPicker
67 |
68 |
69 | - (instancetype _Nullable)initWithTitle:(nullable NSString *)title
70 | delegate:(id _Nullable)delegate
71 | dataSource:(NSArray *)dataSource
72 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
73 | okButtonTitles:(nullable NSString *)sureButtonTitles
74 | handler:(nullable void(^)(NSInteger buttonIndex,
75 | id _Nullable value))handler{
76 |
77 | UIView *currentView = [YWAlertViewHelper currentViewController].view;
78 |
79 | self = [super initWithFrame:currentView.frame];
80 |
81 | if (!self) {
82 | return nil;
83 | }
84 | _handler = handler;
85 | _delegate = delegate;
86 | _listData = [NSMutableArray arrayWithArray:dataSource];
87 | _selectModel = _listData.firstObject;
88 |
89 | self.maskView.frame = currentView.frame;
90 | [self addSubview:_maskView];
91 | self.gaussianBlurOnMaskView.frame = currentView.frame;
92 | [_maskView addSubview:self.gaussianBlurOnMaskView];
93 |
94 | _font = 15;
95 |
96 | _pickerAlertViewWidth = YWAlertScreenW;
97 | _pickerHeight = 160;
98 | UIView *alert = [[UIView alloc] initWithFrame:CGRectMake(0, YWAlertScreenH, _pickerAlertViewWidth , 300)];
99 | alert.autoresizingMask = UIViewAutoresizingFlexibleWidth;
100 | alert.backgroundColor = [UIColor whiteColor];
101 | [self addSubview:alert];
102 | _pickerAlertView = alert;
103 | [self onPrepareAlertViewOnFoot:title cancelButtonTitle:cancelButtonTitle otherButtonTitles:sureButtonTitles frame:currentView.frame];
104 |
105 | return self;
106 |
107 | }
108 | /**
109 | 配合懒加载,即时即地show的时候,回调
110 |
111 | @param handler 回调
112 | */
113 | - (void)showWindowWithHandler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
114 | _handler = handler;
115 | [self show];
116 | }
117 | - (void)show{
118 |
119 | UIWindow *keyWindows = [YWAlertViewHelper getWindow];
120 | [keyWindows addSubview:self];
121 | _isModal = NO;
122 |
123 | [self addConstraint:NSLayoutAttributeLeft equalTo:keyWindows offset:0];
124 | [self addConstraint:NSLayoutAttributeRight equalTo:keyWindows offset:0];
125 | [self addConstraint:NSLayoutAttributeTop equalTo:keyWindows offset:0];
126 | [self addConstraint:NSLayoutAttributeBottom equalTo:keyWindows offset:0];
127 |
128 | if (!_isSetFrame) {
129 | [self setNeedsLayout];
130 | }else{
131 | [UIView animateWithDuration:0.62 animations:^{
132 | CGRect rect1 = self.pickerAlertView.frame;
133 | rect1.origin.y = YWAlertScreenH - rect1.size.height;
134 | self.pickerAlertView.frame = rect1;
135 | }];
136 | }
137 |
138 | _datePicker.delegate = self;
139 | _datePicker.dataSource = self;
140 |
141 | [self selectIndex:self.selectRow inComponent:0 animated:NO];
142 | }
143 | /**
144 | 显示在viewController上
145 | */
146 | - (void)showOnViewController{
147 | self.maskView.backgroundColor = [UIColor clearColor];
148 | [self selectIndex:self.selectRow inComponent:0 animated:NO];
149 | _isModal = YES;
150 | YWContainerViewController *conVC = [YWContainerViewController new];
151 | conVC.alertView = self;
152 | conVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
153 | conVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
154 | [[YWAlertViewHelper currentViewController] presentViewController:conVC animated:NO completion:^{
155 | [UIView animateWithDuration:0.6 animations:^{
156 | CGRect rect1 = self.pickerAlertView.frame;
157 | rect1.origin.y = YWAlertScreenH - rect1.size.height;
158 | self.pickerAlertView.frame = rect1;
159 | }];
160 | }];
161 |
162 | }
163 | - (void)hiddenAlertView{
164 | [UIView animateWithDuration:0.62 animations:^{
165 | CGRect rect1 = self.pickerAlertView.frame;
166 | rect1.origin.y = YWAlertScreenH;
167 | self.pickerAlertView.frame = rect1;
168 | } completion:^(BOOL finished) {
169 | if (self -> _isModal) {
170 | [[YWAlertViewHelper currentViewController] dismissViewControllerAnimated:YES completion:nil];
171 | }else{
172 | [self removeFromSuperview];
173 | }
174 | }];
175 | }
176 | //MARK: ---------------------- action ------------------------------------
177 | -(void)buttionClick:(UIButton *)btn{
178 | if (btn.tag == 101) {
179 | YWSingleGeneralModel *model = [YWSingleGeneralModel new];
180 | model.idc = self.selectModel.idc;
181 | model.displayName = self.selectModel.displayName;
182 | model.displayMenu = self.selectModel.displayMenu;
183 | if (_handler) {
184 | _handler(1,model);
185 | }else{
186 | if ([self.delegate respondsToSelector:@selector(didClickAlertView:value:)]) {
187 | [self.delegate didClickAlertView:1 value:model];
188 | }
189 | }
190 | }
191 | [self hiddenAlertView];
192 | }
193 |
194 | //MARK: ------------------------ UIPickerViewDelegate,UIPickerViewDataSource ---------------------
195 | - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
196 | return 1;
197 | }
198 | - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
199 | return self.listData.count;
200 | }
201 | -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
202 | UILabel *nameLabel = (UILabel *)view;
203 | if (!nameLabel) {
204 | nameLabel = [[UILabel alloc] init];
205 | nameLabel.textAlignment = NSTextAlignmentCenter;
206 | if (_addressColor) {
207 | nameLabel.textColor = _addressColor;
208 | }else{
209 | nameLabel.textColor = [UIColor blackColor];
210 | }
211 | [nameLabel setFont:[UIFont systemFontOfSize:_font]];
212 | [self changeSpearatorLineColor];
213 | }
214 | YWSingleGeneralModel *model = self.listData[row];
215 | nameLabel.text = [NSString stringWithFormat:@"%@",model.displayName];
216 | return nameLabel;
217 | }
218 | -(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
219 | return 36;
220 | }
221 | - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
222 | self.selectModel = self.listData[row];
223 | self.selectRow = row;
224 | }
225 |
226 | //MARK: ------------------------ config配置信息 --------------------------------
227 | /**
228 | 隐藏bodyview上下的两个分隔线
229 | */
230 | - (void)hiddenBodyLineView{
231 |
232 | }
233 | /**
234 | 隐藏所有的分隔线
235 | */
236 | - (void)hiddenAllLineView{
237 |
238 | }
239 | /**
240 | 设置整个弹框的背景颜色
241 |
242 | @param color 颜色
243 | */
244 | - (void)setAlertViewBackgroundColor:(UIColor *)color{
245 | self.pickerAlertView.backgroundColor = color;
246 | }
247 | /**
248 | 设置titleView的背景颜色
249 |
250 | @param color 颜色
251 | */
252 | - (void)setTitleViewBackColor:(UIColor *)color{
253 | self.titleView.backgroundColor = color;
254 | }
255 | /**
256 | 设置titleView的title颜色
257 |
258 | @param color 颜色
259 | */
260 | - (void)setTitleViewTitleColor:(UIColor *)color{
261 | self.titleLabel.textColor = color;
262 | }
263 | /**
264 | 设置message的字体颜色
265 |
266 | @param color 颜色
267 | */
268 | - (void)setMessageTitleColor:(UIColor *)color{
269 |
270 | }
271 | /**
272 | 设置所有按钮的字体颜色
273 |
274 | @param color 颜色
275 | */
276 | - (void)setAllButtionTitleColor:(UIColor *)color{
277 | [self.cancelBtn setTitleColor:color forState:UIControlStateNormal];
278 | [self.sureBtn setTitleColor:color forState:UIControlStateNormal];
279 | }
280 | /**
281 | 设置单个按钮的颜色
282 |
283 | @param color 颜色
284 | @param index 下标
285 | */
286 | - (void)setButtionTitleColor:(UIColor *)color index:(NSInteger)index{
287 | if (index == 0) {
288 | [self.cancelBtn setTitleColor:color forState:UIControlStateNormal];
289 | }else if (index == 1){
290 | [self.sureBtn setTitleColor:color forState:UIControlStateNormal];
291 | }else{
292 | NSAssert(NO, @"当前弹框按钮的小标为0~1,0-取消,1-确定");
293 | }
294 | }
295 | /**
296 | 设置单个按钮的字体以及其大小
297 |
298 | @param name 什么字体
299 | @param size 大小
300 | @param index 小标
301 | */
302 | - (void)setButtionTitleFontWithName:(NSString *)name size:(CGFloat)size index:(NSInteger)index{
303 | if (index == 0) {
304 | if (name) {
305 | self.cancelBtn.titleLabel.font = [UIFont fontWithName:name size:size];
306 | }else{
307 | self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:size];
308 | }
309 | }else if (index == 1){
310 | if (name) {
311 | self.sureBtn.titleLabel.font = [UIFont fontWithName:name size:size];
312 | }else{
313 | self.sureBtn.titleLabel.font = [UIFont systemFontOfSize:size];
314 | }
315 | }else{
316 | NSAssert(NO, @"当前弹框按钮的小标为0~1,0-取消,1-确定");
317 | }
318 |
319 | }
320 | /**
321 | 设置title的字体以及其大小
322 |
323 | @param name 什么字体(为nil时,即是系统字体)
324 | @param size 大小
325 | */
326 | - (void)setTitleFontWithName:(NSString *)name size:(CGFloat)size{
327 | if (name) {
328 | self.titleLabel.font = [UIFont fontWithName:name size:size];
329 | }else{
330 | self.titleLabel.font = [UIFont systemFontOfSize:size];
331 | }
332 | }
333 | /**
334 | 设置message的字体以及其大小
335 |
336 | @param name 什么字体(为nil时,即是系统字体)
337 | @param size 大小
338 | */
339 | - (void)setMessageFontWithName:(NSString *)name size:(CGFloat)size{
340 |
341 | }
342 | /**
343 | 设置picker的高度
344 |
345 | @param height 高度
346 | */
347 | - (void)setPickerHeightOnAddressPickerView:(CGFloat)height{
348 | if (height<=0) {
349 | return;
350 | }
351 | _layPickerViewHeight.constant = height;
352 | _isSetFrame = NO;
353 | [self setNeedsLayout];
354 | }
355 | /**
356 | 设置蒙版的背景图
357 |
358 | @param image 蒙版的背景图(可使用高斯的image)
359 | */
360 | - (void)setGaussianBlurImage:(UIImage *)image{
361 | self.gaussianBlurOnMaskView.image = image;
362 | }
363 | /**
364 | 统一配置信息
365 |
366 | @param theme 主题
367 | */
368 | - (void)setTheme:(id)theme{
369 | NSLog(@"地址选择器目前不支持主题theme设置");
370 | }
371 | - (void)setDefalutOnSingleGeneraPickerView:(YWSingleGeneralModel *)defalutModel{
372 | NSAssert(!(defalutModel==nil), @"defalutModel不能为nil");
373 | YWSingleGeneralModel *tempProinceModel = nil;
374 | int index = 0;
375 | for (YWSingleGeneralModel *model in self.listData) {
376 | if (model.idc == defalutModel.idc) {
377 | tempProinceModel = model;
378 | _selectRow = index;
379 | break;
380 | }
381 | index ++;
382 | }
383 | if (!tempProinceModel) {
384 | tempProinceModel = self.selectModel;
385 | }
386 | self.selectModel = tempProinceModel;
387 | }
388 |
389 | //MARK: --------------------- private method ------------------------
390 | //加载本地bundle资源
391 | - (NSArray *)loadLocationData{
392 | NSBundle *bundle = [NSBundle bundleForClass:[self class]];
393 | NSURL *url = [bundle URLForResource:@"YWAlertView" withExtension:@"bundle"];
394 | NSBundle *plistBundle = [NSBundle bundleWithURL:url];
395 |
396 | NSString *filePath = [plistBundle pathForResource:@"YWCity" ofType:@"plist"];
397 | NSArray *dataSource = [NSArray arrayWithContentsOfFile:filePath];
398 | if (!dataSource || dataSource.count == 0) {
399 | NSAssert(NO, @"加载本地数据异常");
400 | return nil;
401 | }
402 | return dataSource;
403 | }
404 |
405 | - (void)selectIndex:(NSInteger)index inComponent:(NSInteger)component animated:(BOOL)animated{
406 | [self.datePicker selectRow:index inComponent:component animated:animated];
407 | }
408 | - (void)onPrepareAlertViewOnFoot:(nullable NSString *)title
409 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
410 | otherButtonTitles:(nullable NSString *)otherButtonTitles
411 | frame:(CGRect)frame{
412 |
413 | [_pickerAlertView addSubview:self.titleView];
414 | [self.titleView addConstraint:NSLayoutAttributeTop equalTo:_pickerAlertView offset:0];
415 | [self.titleView addConstraint:NSLayoutAttributeLeft equalTo:_pickerAlertView offset:0];
416 | [self.titleView addConstraint:NSLayoutAttributeRight equalTo:_pickerAlertView offset:0];
417 |
418 | _layOnTitleViewHeight = [self.titleView addConstraintAndReturn:NSLayoutAttributeHeight equalTo:nil toAttribute:NSLayoutAttributeHeight offset:titleViewHeight];
419 |
420 | [self.cancelBtn setTitle:cancelButtonTitle forState:UIControlStateNormal];
421 | [self.titleView addSubview:_cancelBtn];
422 |
423 | [self.sureBtn setTitle:otherButtonTitles forState:UIControlStateNormal];
424 | [self.titleView addSubview:_sureBtn];
425 |
426 | [_cancelBtn addConstraint:NSLayoutAttributeTop equalTo:self.titleView offset:0];
427 | [_cancelBtn addConstraint:NSLayoutAttributeBottom equalTo:self.titleView offset:0];
428 | [_cancelBtn addConstraint:NSLayoutAttributeLeft equalTo:self.titleView offset:10];
429 | [_cancelBtn addConstraint:NSLayoutAttributeWidth equalTo:nil toAttribute:NSLayoutAttributeWidth offset:60];
430 |
431 | [_sureBtn addConstraint:NSLayoutAttributeTop equalTo:self.titleView offset:0];
432 | [_sureBtn addConstraint:NSLayoutAttributeBottom equalTo:self.titleView offset:0];
433 | [_sureBtn addConstraint:NSLayoutAttributeRight equalTo:self.titleView toAttribute:NSLayoutAttributeRight offset:-10];
434 | [_sureBtn addConstraint:NSLayoutAttributeWidth equalTo:nil toAttribute:NSLayoutAttributeWidth offset:60];
435 |
436 |
437 | self.titleLabel.text = title;
438 | [self.titleView addSubview:self.titleLabel];
439 | [self.titleLabel addConstraint:NSLayoutAttributeTop equalTo:self.titleView offset:0];
440 | [self.titleLabel addConstraint:NSLayoutAttributeBottom equalTo:self.titleView offset:0];
441 | [self.titleLabel addConstraint:NSLayoutAttributeLeft equalTo:_cancelBtn toAttribute:NSLayoutAttributeRight offset:10];
442 | [self.titleLabel addConstraint:NSLayoutAttributeRight equalTo:_sureBtn toAttribute:NSLayoutAttributeLeft offset:-10];
443 |
444 |
445 | //添加pickerView
446 | [_pickerAlertView addSubview:self.messageLabel];
447 | [_messageLabel addConstraint:NSLayoutAttributeLeft equalTo:_pickerAlertView offset:0];
448 | [_messageLabel addConstraint:NSLayoutAttributeRight equalTo:_pickerAlertView offset:0];
449 | [_messageLabel addConstraint:NSLayoutAttributeTop equalTo:self.titleView toAttribute:NSLayoutAttributeBottom offset:0];
450 | _layPickerViewHeight = [_messageLabel addConstraintAndReturn:NSLayoutAttributeHeight equalTo:nil toAttribute:NSLayoutAttributeHeight offset:_pickerHeight];
451 |
452 | [_messageLabel addSubview:self.datePicker];
453 |
454 | [_datePicker addConstraint:NSLayoutAttributeLeft equalTo:_messageLabel offset:0];
455 | [_datePicker addConstraint:NSLayoutAttributeRight equalTo:_messageLabel offset:0];
456 | [_datePicker addConstraint:NSLayoutAttributeBottom equalTo:_messageLabel offset:0];
457 | [_datePicker addConstraint:NSLayoutAttributeTop equalTo:_messageLabel offset:0];
458 |
459 | }
460 | //改变分割线的颜色
461 | - (void)changeSpearatorLineColor{
462 | if (!_isSetSpeartorView) {
463 | for(UIView *speartorView in self.datePicker.subviews){
464 | if (speartorView.frame.size.height < 1){//取出分割线view
465 | speartorView.backgroundColor = DefaultLineTranslucenceColor;//隐藏分割线
466 | }
467 | }
468 | _isSetSpeartorView = YES;
469 | }
470 | }
471 | - (void)setSheetFrame{
472 |
473 | [self.titleView layoutIfNeeded];
474 | [self.messageLabel layoutIfNeeded];
475 |
476 | CGFloat heigth = CGRectGetHeight(self.titleView.frame) + CGRectGetHeight(self.messageLabel.frame);
477 | CGRect rect = self.pickerAlertView.frame;
478 | rect.size.height = heigth;
479 | self.pickerAlertView.frame = rect;
480 |
481 | [UIView animateWithDuration:0.62 animations:^{
482 | CGRect rect1 = self.pickerAlertView.frame;
483 | rect1.origin.y = YWAlertScreenH - heigth;
484 | self.pickerAlertView.frame = rect1;
485 | }];
486 |
487 | _isSetFrame = YES;
488 |
489 | }
490 | //MARK: --------------------- gertter & setter ------------------------
491 | - (UIView *)maskView{
492 | if (!_maskView) {
493 | _maskView = [[UIView alloc] initWithFrame:CGRectZero];
494 | _maskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
495 | _maskView.backgroundColor = [UIColor colorWithRed:10 / 255.0 green:10 / 255.0 blue:10 / 255.0 alpha:0.6];
496 | }
497 | return _maskView;
498 | }
499 | - (UIImageView *)gaussianBlurOnMaskView{
500 | if (!_gaussianBlurOnMaskView) {
501 | _gaussianBlurOnMaskView = [UIImageView new];
502 | _gaussianBlurOnMaskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
503 | _gaussianBlurOnMaskView.hidden = YES;
504 | }
505 | return _gaussianBlurOnMaskView;
506 | }
507 |
508 | - (UIView *)titleView{
509 | if (!_titleView) {
510 | _titleView = [UIView new];
511 | }
512 | return _titleView;
513 | }
514 |
515 | - (UILabel *)titleLabel{
516 | if (!_titleLabel) {
517 | _titleLabel = [UILabel new];
518 | _titleLabel.textAlignment = NSTextAlignmentCenter;
519 | _titleLabel.font = [UIFont systemFontOfSize:16];
520 | _titleLabel.text = @"请选择地址";
521 | }
522 | return _titleLabel;
523 | }
524 | - (UILabel *)messageLabel{
525 | if (!_messageLabel) {
526 | _messageLabel = [UILabel new];
527 | _messageLabel.textAlignment = NSTextAlignmentCenter;
528 | _messageLabel.font = [UIFont boldSystemFontOfSize:100];
529 | _messageLabel.textColor = [UIColor colorWithRed:233/255.0 green:237/255.0 blue:242/255.0 alpha:0.9];
530 | _messageLabel.userInteractionEnabled = YES;
531 | }
532 | return _messageLabel;
533 | }
534 | - (UIButton *)cancelBtn{
535 | if (!_cancelBtn) {
536 | _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
537 | _cancelBtn.tag = 100;
538 | _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
539 | [_cancelBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
540 | [_cancelBtn addTarget:self action:@selector(buttionClick:) forControlEvents:UIControlEventTouchUpInside];
541 | }
542 | return _cancelBtn;
543 | }
544 | - (UIButton *)sureBtn{
545 | if (!_sureBtn) {
546 | _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
547 | _sureBtn.tag = 101;
548 | _sureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
549 | [_sureBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
550 | [_sureBtn addTarget:self action:@selector(buttionClick:) forControlEvents:UIControlEventTouchUpInside];
551 | }
552 | return _sureBtn;
553 | }
554 | -(UIPickerView *)datePicker {
555 | if (!_datePicker) {
556 | _datePicker = [[UIPickerView alloc] initWithFrame:CGRectZero];
557 | _datePicker.delegate = self;
558 | _datePicker.dataSource = self;
559 | _datePicker.showsSelectionIndicator = NO;
560 | }
561 | return _datePicker;
562 | }
563 |
564 |
565 | - (void)layoutSubviews{
566 | [super layoutSubviews];
567 | [self setSheetFrame];
568 | }
569 | @end
570 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
74 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
107 |
116 |
125 |
134 |
140 |
146 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
172 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
--------------------------------------------------------------------------------
/YWAlertViewDemo/YWAlertViewDemo/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/27.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "YWAlertView.h"
11 | #import "YWTheme.h"
12 | #import "UIImage+YW.h"
13 |
14 | @interface ViewController ()
15 |
16 | @property (nonatomic, strong) NSMutableArray *list;
17 | //Alert懒加载演示
18 | @property (nonatomic,strong) id ywAlert;
19 | //sheet懒加载演示
20 | @property (nonatomic,strong) id sheetAlert;
21 | //Address懒加载演示
22 | @property (nonatomic,strong) id alert;
23 | //date懒加载演示
24 | @property (nonatomic,strong) id dateAlert;
25 |
26 |
27 | @end
28 |
29 | int i = 0;
30 |
31 | @implementation ViewController
32 |
33 | - (void)viewDidLoad {
34 | [super viewDidLoad];
35 | [self initData];
36 |
37 |
38 | UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
39 | tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
40 | tableView.dataSource = self;
41 | tableView.delegate = self;
42 | [self.view addSubview:tableView];
43 |
44 | tableView.backgroundColor = [UIColor cyanColor];
45 |
46 | }
47 |
48 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
49 | return self.list.count;
50 | }
51 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
52 | NSDictionary *dict = self.list[section];
53 | return [[dict objectForKey:@"msg"] count];
54 | }
55 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
56 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
57 | if(!cell){
58 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
59 | cell.textLabel.font = [UIFont systemFontOfSize:13];
60 | }
61 | NSDictionary *dict = self.list[indexPath.section];
62 | NSArray *sAr = [dict objectForKey:@"msg"];
63 | cell.textLabel.text = [sAr objectAtIndex:indexPath.row];
64 | return cell;
65 | }
66 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
67 | UILabel *view = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
68 | NSDictionary *dict = self.list[section];
69 |
70 | view.text = [dict objectForKey:@"section"];
71 |
72 | return view;
73 | }
74 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
75 | return 30;
76 | }
77 |
78 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
79 | [tableView deselectRowAtIndexPath:indexPath animated:YES];
80 | if (indexPath.section == 0) {
81 | switch (indexPath.row) {
82 | case 0:
83 | [self alert_defalut];
84 | break;
85 | case 1:
86 | [self alert_vertical];
87 | break;
88 | case 2:
89 | [self alert_defalut_close];
90 | break;
91 | case 3:
92 | [self alert_defalut_body_custom];
93 | break;
94 | case 4:
95 | [self alert_defalut_body_theme];
96 | break;
97 | case 5:
98 | [self alert_defalut_body_VC];
99 | break;
100 | case 6:
101 | [self alert_Segmentation_fontName];
102 | break;
103 | case 7:
104 | [self alert_not_title];
105 | break;
106 | case 8:
107 | [self alert_defalut_lazing];
108 | break;
109 |
110 | default:
111 | break;
112 | }
113 | }else if (indexPath.section == 1){
114 | switch (indexPath.row) {
115 | case 0:
116 | [self sheet_defalut];
117 | break;
118 | case 1:
119 | [self sheet_no_title];
120 | break;
121 | case 2:
122 | [self sheet_no_msg];
123 | break;
124 | case 3:
125 | [self sheet_no_other];
126 | break;
127 | case 4:
128 | [self sheet_no_canlcel];
129 | break;
130 |
131 | default:
132 | break;
133 | }
134 | }else if (indexPath.section == 2){
135 | switch (indexPath.row) {
136 | case 0:
137 | [self date_defalut];
138 | break;
139 | case 1:
140 | [self date_defalut_Vertical];
141 | break;
142 | case 2:
143 | [self date_defalut_once];
144 | break;
145 | case 3:
146 | [self date_defalut_yearMoth];
147 | break;
148 | case 4:
149 | [self date_defalut_hourMinuteSecond];
150 | break;
151 | case 5:
152 | [self date_defalut_foot];
153 | break;
154 | case 6:
155 | [self date_defalut_yearMonthDay_foot];
156 | break;
157 |
158 | default:
159 | break;
160 | }
161 | }else if (indexPath.section == 3){
162 | switch (indexPath.row) {
163 | case 0:
164 | [self address_defalut];
165 | break;
166 | case 1:
167 | [self address_defalut_lazing];
168 | break;
169 | case 2:
170 | [self address_defalut_modityHeight];
171 | break;
172 | case 3:
173 | [self address_setting_defalutValue];
174 | break;
175 | case 4:
176 | [self address_mode1_defalutValue];
177 | break;
178 |
179 |
180 | default:
181 | break;
182 | }
183 | }
184 |
185 |
186 |
187 | }
188 | - (id)ywAlert{
189 | if (!_ywAlert) {
190 | _ywAlert = [YWAlertView alertViewWithTitle:nil message:@"message" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
191 | }
192 | return _ywAlert;
193 | }
194 | - (void)alert_defalut_lazing{
195 | [(id)self.ywAlert resetAlertMessage:@"懒加载模式,我要重置message的信息,高度也要进行相关的变化哦"];
196 | [(id)self.ywAlert resetAlertTitle:@"使用第一行的对象alter"];
197 | [self.ywAlert show];
198 | }
199 | - (void)alert_defalut{
200 | if (i == 0) {
201 | [self.ywAlert show];
202 | }else if (i == 1){
203 | [(id)self.ywAlert resetAlertTitle:@"第一行的对象alter"];
204 | [(id)self.ywAlert resetAlertMessage:@"message"];
205 | [self.ywAlert showOnViewController];
206 | }else{
207 | [(id)self.ywAlert resetAlertTitle:@"第一行的对象alter"];
208 | [(id)self.ywAlert resetAlertMessage:@"懒加载模式,我要重置message的信息,高度也要进行相关的变化哦"];
209 | [self.ywAlert show];
210 | }
211 | i ++;
212 | }
213 | - (void)alert_vertical{
214 |
215 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view,typically from a nib.Do any additional setup after loading the view," delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleVertical bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok",@"other"]];
216 | [alert setMessageFontWithName:@"BodoniSvtyTwoITCTT-BookIta" size:16];
217 | [alert show];
218 |
219 | }
220 | - (void)alert_defalut_close{
221 |
222 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view,typically from a nib" preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:nil otherButtonTitles:nil handler:^(NSInteger buttonIndex, id _Nullable value) {
223 | NSLog(@"block=当前点击--%zi",buttonIndex);
224 | }];
225 | [alert setMessageFontWithName:@"Bodoni Ornaments" size:15];
226 | [(id)alert showCloseOnTitleView];
227 | [alert show];
228 | }
229 | - (void)alert_defalut_body_custom{
230 |
231 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:nil delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleCustom cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok",@"other"]];
232 |
233 | UIView *view = [UIView new];
234 |
235 | UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"自定义的body",@"自定义的body"]];
236 | seg.selectedSegmentIndex = 0;
237 | seg.frame = CGRectMake(20, 20, 200, 30);
238 | [view addSubview:seg];
239 | [(id)alert setCustomBodyView:view height:80];
240 | [alert show];
241 | }
242 |
243 | - (void)alert_defalut_body_theme{
244 |
245 | id alert = [YWAlertView alertViewWithTitle:@"Warm prompt" message:@"Theme configuration color and background map" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
246 | [alert setTheme:[YWTheme new]];
247 | [alert hiddenAllLineView];
248 | [alert hiddenBodyLineView];
249 |
250 | [alert show];
251 | }
252 | - (void)alert_defalut_body_VC{
253 |
254 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"主题配置颜色以及背景图" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
255 | [alert setTheme:[YWTheme new]];
256 | [alert showOnViewController];
257 | }
258 |
259 | - (void)alert_Segmentation_fontName{
260 |
261 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleSegmentation bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
262 | [alert setButtionTitleFontWithName:@"AmericanTypewriter" size:16 index:1];
263 | [alert setButtionTitleFontWithName:@"AmericanTypewriter-Bold" size:16 index:0];
264 |
265 | [alert show];
266 | }
267 | - (void)alert_not_title{
268 |
269 | id alert = [YWAlertView alertViewWithTitle:nil message:@"Do any additional setup after loading the view" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
270 | [alert setButtionTitleFontWithName:@"AmericanTypewriter" size:16 index:1];
271 | [alert setButtionTitleFontWithName:@"AmericanTypewriter-Bold" size:16 index:0];
272 |
273 | [alert show];
274 | }
275 |
276 | - (id)sheetAlert{
277 | if (!_sheetAlert) {//@"温馨提示"
278 | _sheetAlert = [YWAlertView alertViewWithTitle:@"温馨提示" message:nil delegate:self preferredStyle:YWAlertViewStyleActionSheet footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
279 | }
280 | return _sheetAlert;
281 | }
282 |
283 | - (void)sheet_defalut{
284 | // id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view,setup after loading the view,setup after loading the view" delegate:self preferredStyle:YWAlertViewStyleActionSheet footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
285 | [(id)self.sheetAlert resetAlertTitle:@"温馨提示"];
286 | [(id)self.sheetAlert resetAlertMessage:@"Do any additional setup after loading the view,setup after loading the view,setup after loading the view"];
287 | [self.sheetAlert show];
288 | }
289 | - (void)sheet_no_title{
290 | // id alert = [YWAlertView alertViewWithTitle:nil message:@"Do any additional setup after loading the view,setup after loading the view,setup after loading the view" delegate:self preferredStyle:YWAlertViewStyleActionSheet footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
291 |
292 | [self.sheetAlert setMessageFontWithName:@"BradleyHandITCTT-Bold" size:20];
293 | [(id)self.sheetAlert resetAlertMessage:@"懒加载演示修改message,同时修改头部"];
294 | [(id)self.sheetAlert resetAlertTitle:nil];
295 |
296 | [self.sheetAlert show];
297 | }
298 |
299 | - (void)sheet_no_msg{
300 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:nil delegate:self preferredStyle:YWAlertViewStyleActionSheet footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
301 | [alert setMessageTitleColor:[UIColor redColor]];
302 | [alert show];
303 | }
304 | - (void)sheet_no_other{
305 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"没有其他按钮" delegate:self preferredStyle:YWAlertViewStyleActionSheet footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:nil];
306 | [alert show];
307 | }
308 | - (void)sheet_no_canlcel{
309 | id alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"没有取消按钮" delegate:self preferredStyle:YWAlertViewStyleActionSheet footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:nil otherButtonTitles:@[@"other 1",@"other 2"]];
310 | [alert show];
311 | }
312 | - (void)date_defalut{
313 | id alert = [YWAlertView alertViewWithTitle:@"请选择日期" preferredStyle:YWAlertViewStyleDatePicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertStyleShowYearMonthDayHourMinuteSecond cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id _Nullable value) {
314 |
315 | }];
316 | [alert setTitleViewTitleColor:[UIColor redColor]];
317 | [alert show];
318 | }
319 | - (void)date_defalut_Vertical{
320 | id alert = [YWAlertView alertViewWithTitle:@"请选择日期" preferredStyle:YWAlertViewStyleDatePicker footStyle:YWAlertPublicFootStyleVertical bodyStyle:YWAlertStyleShowYearMonthDayHourMinute cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id _Nullable value) {
321 |
322 | }];
323 | [alert show];
324 | }
325 | - (void)date_defalut_once{
326 | id alert = [YWAlertView alertViewWithTitle:@"请选择日期" preferredStyle:YWAlertViewStyleDatePicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertStyleShowYearMonthDay cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id _Nullable value) {
327 |
328 | }];
329 | [alert setGaussianBlurImage:[UIImage yw_blurImage:[UIImage imageNamed:@"bg_fuweus"] blur:1]];
330 | [alert showOnViewController];
331 | }
332 |
333 | - (void)date_defalut_yearMoth{
334 | id alert = [YWAlertView alertViewWithTitle:@"请选择日期" preferredStyle:YWAlertViewStyleDatePicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertStyleShowYearMonth cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id _Nullable value) {
335 | NSLog(@"选择日期 %@",value);
336 | }];
337 | [alert setGaussianBlurImage:[UIImage yw_blurImage:[UIImage imageNamed:@"bg_fuweus"] blur:1]];
338 | [alert showOnViewController];
339 | }
340 | - (void)date_defalut_hourMinuteSecond{
341 | id alert = [YWAlertView alertViewWithTitle:@"请选择日期" preferredStyle:YWAlertViewStyleDatePicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertStyleShowHourMinuteSecond cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id _Nullable value) {
342 | NSLog(@"选择日期 %@",value);
343 | }];
344 | [alert setGaussianBlurImage:[UIImage yw_blurImage:[UIImage imageNamed:@"bg_fuweus"] blur:1]];
345 | [alert showOnViewController];
346 | }
347 | - (void)date_defalut_foot{
348 | //懒加载模式演示
349 | [(id)self.dateAlert setPickerHeightOnDatePickerView:300];
350 | [self.dateAlert show];
351 |
352 |
353 | }
354 | - (void)date_defalut_yearMonthDay_foot{
355 | //懒加载模式演示
356 | [self.dateAlert show];
357 |
358 | }
359 |
360 | - (id)dateAlert{
361 | if (!_dateAlert) {
362 | _dateAlert = [YWAlertView alertViewWithTitle:@"请选择日期" preferredStyle:YWAlertViewStyleDatePicker2 footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertStyleShowYearMonthDay cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id _Nullable value) {
363 | NSLog(@"选择日期 %@",value);
364 | }];
365 | }
366 | return _dateAlert;
367 | }
368 |
369 | - (void)address_defalut{
370 |
371 | id alert = [YWAlertView alertViewWithTitle:@"请选择地区" message:nil preferredStyle:YWAlertViewStyleAddressPicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertAddressPickerShowArea cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(NSInteger buttonIndex, id _Nullable value) {
372 |
373 | }];
374 |
375 | [alert show];
376 | }
377 | - (void)address_defalut_lazing{
378 | // id alert = [YWAlertView alertViewWithTitle:@"请选择地区" message:nil preferredStyle:YWAlertViewStyleAddressPicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertAddressPickerShowArea cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(NSInteger buttonIndex, id _Nullable value) {
379 | //
380 | // }];
381 | //支持懒加载
382 | [self.alert show];
383 | }
384 | - (void)address_defalut_modityHeight{
385 |
386 | idnewAlert = (id)self.alert;
387 |
388 | [newAlert setPickerHeightOnAddressPickerView:220];
389 | //支持懒加载
390 | [self.alert show];
391 | }
392 |
393 | - (void)address_setting_defalutValue{
394 | id alert = [YWAlertView alertViewWithTitle:@"请选择地区" message:nil preferredStyle:YWAlertViewStyleAddressPicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertAddressPickerShowArea cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(NSInteger buttonIndex, id _Nullable value) {
395 |
396 | }];
397 | #warning 强转协议的原因
398 | ///继承于
399 | ///强转,以便调用的私有方法
400 | idnewAlert = (id)alert;
401 | YWResultModel *reModel = [YWResultModel new];
402 | YWProvinceModel *pModel = [YWProvinceModel new];
403 | pModel.name = @"广东省";
404 | reModel.province = pModel;
405 | [newAlert setDefalutOnAddressPickerView:reModel];
406 | [alert show];
407 | }
408 | - (void)address_mode1_defalutValue{
409 | id alert = [YWAlertView alertViewWithTitle:@"请选择地区" message:nil preferredStyle:YWAlertViewStyleAddressPicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertAddressPickerShowCity cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(NSInteger buttonIndex, id _Nullable value) {
410 |
411 | }];
412 | [alert show];
413 |
414 | // YWSingleGeneralModel *model = [YWSingleGeneralModel new];
415 | // model.idc = 1;
416 | // model.displayName = @"1岁";
417 | //
418 | //
419 | // YWSingleGeneralModel *model1 = [YWSingleGeneralModel new];
420 | // model1.idc = 2;
421 | // model1.displayName = @"2岁";
422 | //
423 | // YWSingleGeneralModel *model2 = [YWSingleGeneralModel new];
424 | // model2.idc = 3;
425 | // model2.displayName = @"3岁";
426 | //
427 | //
428 | // id alert = [YWAlertView alertViewWithTitle:@"请选择" dataSource:@[model,model1,model2] cancelButtonTitle:@"取消" sureButtonTitles:@"确定" handler:^(NSInteger buttonIndex, id _Nullable value) {
429 | // YWSingleGeneralModel *s = value;
430 | // NSLog(@"---%@",s.displayName);
431 | // }];
432 | // [alert setDefalutOnSingleGeneraPickerView:model1];
433 | // [alert show];
434 | }
435 |
436 |
437 |
438 | - (id)alert{
439 | if (!_alert) {
440 | _alert = [YWAlertView alertViewWithTitle:@"请选择地区" message:nil preferredStyle:YWAlertViewStyleAddressPicker footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertAddressPickerShowArea cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(NSInteger buttonIndex, id _Nullable value) {
441 |
442 | }];
443 | }
444 | return _alert;
445 | }
446 |
447 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
448 |
449 |
450 | /*
451 | UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"获取图片" message:@"00000" preferredStyle: UIAlertControllerStyleActionSheet];
452 |
453 |
454 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
455 |
456 |
457 |
458 | UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"打开照相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
459 |
460 |
461 | }];
462 |
463 |
464 |
465 | [alertController addAction:cancelAction];
466 |
467 |
468 |
469 | [alertController addAction:deleteAction];
470 |
471 |
472 |
473 | // [alertController addAction:archiveAction];
474 |
475 |
476 | [self presentViewController:alertController animated:YES completion:nil];
477 |
478 | */
479 |
480 | }
481 | - (void)initData{
482 | self.list = @[].mutableCopy;
483 | [self.list addObject:@{@"section":@" alter模式",@"msg":@[@"YWAlertViewStyleAlert模式下的YWAlertPublicStyleDefalut",@"YWAlertViewStyleAlert模式下的YWAlertPublicStyleVertical",@"YWAlertViewStyleAlert模式下的各个模式均可以显示CloseBtn",@"YWAlertViewStyleAlert模式下的YWAlertPublicBodyStyleCustom",@"YWAlertViewStyleAlert模式下的theme主题配置基本信息",@"YWAlertViewStyleAlert显示控制器上",@"YWAlertViewStyleAlert的YWAlertPublicFootStyleSegmentation字号及其大小",@"YWAlertViewStyleAlert的没有title",@"开始支持懒加载,同时支持修改title以及message,高度动态变化"]}];
484 |
485 | [self.list addObject:@{@"section":@" sheet模式",@"msg":@[@"YWAlertViewStyleActionSheet模式下",@"YWAlertViewStyleActionSheet模式下没有头部情况下",@"YWAlertViewStyleActionSheet模式下没有message情况下",@"YWAlertViewStyleActionSheet模式下没有other情况下",@"YWAlertViewStyleActionSheet模式下没有cancel情况下"]}];
486 |
487 | [self.list addObject:@{@"section":@" date模式",@"msg":@[@"中心显示日期选择器年月日时分秒",@"中心显示日期选择器年月日时分",@"中心显示日期选择器年月日",@"中心显示日期选择器年月",@"中心显示日期选择器时分秒",@"底部显示日期选择器年月日时分秒",@"底部显示日期选择器年月日",]}];
488 |
489 | [self.list addObject:@{@"section":@" address模式",@"msg":@[@"省市区显示",@"懒加载模式",@"修改懒加载alert的高度",@"强转协议,调用专属的方法",@"省市模式"]}];
490 |
491 |
492 | }
493 |
494 | - (void)didClickAlertView:(NSInteger)buttonIndex value:(id)value{
495 | NSLog(@"委托代理=当前点击--%zi",buttonIndex);
496 |
497 | }
498 | - (void)didReceiveMemoryWarning {
499 | [super didReceiveMemoryWarning];
500 | // Dispose of any resources that can be recreated.
501 | }
502 |
503 |
504 | @end
505 |
--------------------------------------------------------------------------------
/YWAlertView/YWActionSheet.m:
--------------------------------------------------------------------------------
1 | //
2 | // YWActionSheet.m
3 | // YWAlertViewDemo
4 | //
5 | // Created by yaowei on 2018/8/30.
6 | // Copyright © 2018年 yaowei. All rights reserved.
7 | //
8 |
9 | #import "YWActionSheet.h"
10 | #import "YWAlertViewHelper.h"
11 | #import "UIView+Autolayout.h"
12 |
13 | static const float btnHeight = 45;
14 |
15 |
16 |
17 | @interface YWActionSheet ()
18 | {
19 | CGFloat _alterWidth;
20 | //装lineView的集合(包括所有的lineView)
21 | NSMutableArray *_lineList;
22 | //装body上下的两个lineView;
23 | NSMutableArray *_bodyLineList;
24 | // alertView的背景view
25 | UIImageView *_backgroundAlterView;
26 | BOOL _isModal;
27 | UIColor *_backgroundColor;
28 | UIView *_upperView;//上部分
29 | CGFloat _bottomValue;//距离底部的值
30 | CGFloat _boundsHeight;
31 | NSInteger _isNeedLayout;//0-默认,没有开始布局,1-已经布局过,由于设置message,需要重新刷新布局,2-布局已完成
32 | }
33 | //sheet的容器
34 | @property (nonatomic, strong) UIView *sheetView;
35 | //蒙层
36 | @property (nonatomic, strong) UIView *maskView;
37 | //高斯模糊的背景图
38 | @property (nonatomic, strong) UIImageView *gaussianBlurOnMaskView;
39 | //标题的view
40 | @property (nonatomic, strong) UIView *titleView;
41 | //标题
42 | @property (nonatomic, strong) UILabel *titleLabel;
43 | //描述的容器
44 | @property (nonatomic, strong) UIView *messageContainerView;
45 | //描述
46 | @property (nonatomic, strong) UILabel *messageLabel;
47 | //其他按钮的容器
48 | @property (nonatomic, strong) UIView *otherContainerView;
49 | //取消按钮的容器
50 | @property (nonatomic, strong) UIView *cancelContainerView;
51 | //取消按钮
52 | @property (nonatomic, strong) UIButton *cancelBtn;
53 | //按钮的集合
54 | @property (nonatomic, strong) NSMutableArray *buttionList;
55 |
56 | @property (nonatomic, copy) void(^handler)(NSInteger buttonIndex,id value);
57 |
58 | @end
59 |
60 | @implementation YWActionSheet
61 |
62 | - (instancetype _Nullable )initWithTitle:(nullable NSString *)title
63 | message:(nullable NSString *)message
64 | delegate:(id _Nullable )delegate
65 | footStyle:(YWAlertPublicFootStyle)footStyle
66 | bodyStyle:(YWAlertPublicBodyStyle)bodyStyle
67 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
68 | otherButtonTitles:(nullable NSArray *)otherButtonTitles
69 | handler:(nullable void(^)(NSInteger buttonIndex,
70 | id _Nullable value))handler{
71 |
72 | UIView *currentView = [YWAlertViewHelper currentViewController].view;
73 | self = [super initWithFrame:currentView.frame];
74 |
75 | if (!self) {
76 | return nil;
77 | }
78 |
79 | _handler = handler;
80 | _delegate = delegate;
81 | _bodyLineList = @[].mutableCopy;
82 | _lineList = @[].mutableCopy;
83 | _buttionList = @[].mutableCopy;
84 |
85 | //蒙层及其背景
86 | self.maskView.frame = currentView.frame;
87 | [self addSubview:_maskView];
88 | self.gaussianBlurOnMaskView.frame = currentView.frame;
89 | [_maskView addSubview:self.gaussianBlurOnMaskView];
90 |
91 | //整个sheet
92 | // UIView *sheet = [[UIView alloc] initWithFrame:CGRectMake(0, currentView.frame.size.height,currentView.frame.size.width, 300)];
93 | UIView *sheet = [[UIView alloc] initWithFrame:CGRectMake(0, currentView.frame.size.height,currentView.frame.size.width, 300)];
94 |
95 | sheet.autoresizingMask = UIViewAutoresizingFlexibleWidth;
96 | sheet.backgroundColor = [UIColor clearColor];
97 | self.sheetView = sheet;
98 | [self addSubview:sheet];
99 |
100 | [self onPrepareTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles frame:currentView.frame];
101 |
102 | return self;
103 | }
104 | //MARK: ---------------------- show&hdien ----------------------------
105 | - (void)show{
106 |
107 | UIWindow *keyWindows = [YWAlertViewHelper getWindow];
108 | _boundsHeight = keyWindows.bounds.size.height;
109 | [keyWindows addSubview:self];
110 | _isModal = NO;
111 |
112 | [self addConstraint:NSLayoutAttributeLeft equalTo:keyWindows offset:0];
113 | [self addConstraint:NSLayoutAttributeRight equalTo:keyWindows offset:0];
114 | [self addConstraint:NSLayoutAttributeTop equalTo:keyWindows offset:0];
115 | [self addConstraint:NSLayoutAttributeBottom equalTo:keyWindows offset:0];
116 |
117 | if (_isNeedLayout == 0) {
118 | [self layoutIfNeeded];
119 | }else if(_isNeedLayout == 1){
120 | [self layoutIfNeeded];
121 | }
122 | __weak typeof(self)weakSelf = self;
123 | [UIView animateWithDuration:0.7 animations:^{
124 |
125 | CGRect sheetFrame = weakSelf.sheetView.frame;
126 |
127 | sheetFrame.origin.y = keyWindows.bounds.size.height - sheetFrame.size.height;
128 |
129 | weakSelf.sheetView.frame = sheetFrame;
130 |
131 | } completion:^(BOOL finished) {
132 |
133 | }];
134 |
135 | }
136 | - (void)showOnViewController{
137 | [self show];
138 | }
139 | /**
140 | 配合懒加载,即时即地show的时候,回调
141 |
142 | @param handler 回调
143 | */
144 | - (void)showWindowWithHandler:(nullable void(^)(NSInteger buttonIndex,id _Nullable value))handler{
145 | _handler = handler;
146 | [self show];
147 | }
148 | - (void)hiddenAlertView{
149 |
150 | __weak typeof(self)weakSelf = self;
151 |
152 | CGRect frame = self.sheetView.frame;
153 |
154 | frame.origin.y = _boundsHeight;
155 |
156 | [UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:0.8 options:0 animations:^{
157 | weakSelf.sheetView.frame = frame;
158 | weakSelf.maskView.alpha = 0.0f;
159 | } completion:^(BOOL finished) {
160 | [weakSelf removeFromSuperview];
161 | weakSelf.maskView.alpha = 1;
162 | }];
163 | }
164 | //MARK: ---------------------- action ------------------------------------
165 | - (void)buttionClick:(UIButton *)btn{
166 | [self hiddenAlertView];
167 | if (_handler) {
168 | _handler(btn.tag - 100,btn.titleLabel.text);
169 | }
170 | if (_delegate && [_delegate respondsToSelector:@selector(didClickAlertView:value:)]) {
171 | [_delegate didClickAlertView:btn.tag - 100 value:btn.titleLabel.text];
172 | }
173 | }
174 |
175 | //MARK: --------------------- private method ------------------------
176 | //准备布局
177 | - (void)onPrepareTitle:(nullable NSString *)title
178 | message:(nullable NSString *)message
179 | cancelButtonTitle:(nullable NSString *)cancelButtonTitle
180 | otherButtonTitles:(nullable NSArray *)otherButtonTitles
181 | frame:(CGRect)frame{
182 |
183 | _backgroundColor = [UIColor whiteColor];
184 |
185 | _upperView = [UIView new];
186 | _upperView.backgroundColor = [UIColor clearColor];
187 | _upperView.layer.cornerRadius = 15;
188 | _upperView.layer.masksToBounds = YES;
189 | [self.sheetView addSubview:_upperView];
190 |
191 | [_upperView addConstraint:NSLayoutAttributeLeft equalTo:self.sheetView offset:10];
192 | [_upperView addConstraint:NSLayoutAttributeRight equalTo:self.sheetView offset:-10];
193 | [_upperView addConstraint:NSLayoutAttributeTop equalTo:self.sheetView offset:0];
194 |
195 | //头部设置
196 | _titleView = [UIView new];
197 | _titleView.backgroundColor = [UIColor whiteColor];
198 | [_upperView addSubview:_titleView];
199 |
200 | [_titleView addConstraint:NSLayoutAttributeLeft equalTo:_upperView offset:0];
201 | [_titleView addConstraint:NSLayoutAttributeRight equalTo:_upperView offset:0];
202 | [_titleView addConstraint:NSLayoutAttributeTop equalTo:_upperView offset:0];
203 |
204 | // if (title && title.length > 0) {
205 | _titleView.backgroundColor = [UIColor whiteColor];
206 | if (title && title.length > 0) {
207 | self.titleLabel.text = [NSString stringWithFormat:@"\r\n%@\r\n",title];
208 | }
209 | // self.titleLabel.text = title;
210 | [_titleView addSubview:self.titleLabel];
211 |
212 | [self.titleLabel addConstraint:NSLayoutAttributeLeft equalTo:_titleView offset:10];
213 | [self.titleLabel addConstraint:NSLayoutAttributeRight equalTo:_titleView offset:-10];
214 | // [self.titleLabel addConstraint:NSLayoutAttributeTop equalTo:_titleView offset:14];
215 | [self.titleLabel addConstraint:NSLayoutAttributeTop equalTo:_titleView offset:0];
216 |
217 | UIView *lineTop = [UIView new];
218 | lineTop.backgroundColor = DefaultLineTranslucenceColor;
219 | [_titleView addSubview:lineTop];
220 | [_bodyLineList addObject:lineTop];
221 |
222 | [lineTop addConstraint:NSLayoutAttributeLeft equalTo:_titleView offset:0];
223 | [lineTop addConstraint:NSLayoutAttributeRight equalTo:_titleView offset:0];
224 | [lineTop addConstraint:NSLayoutAttributeBottom equalTo:_titleView offset:0];
225 | [lineTop addConstraint:NSLayoutAttributeHeight equalTo:nil offset:1];
226 |
227 | [_titleView addConstraint:NSLayoutAttributeHeight equalTo:self.titleLabel offset:1];
228 |
229 | // [_titleView addConstraint:NSLayoutAttributeHeight equalTo:self.titleLabel offset:28+1];
230 |
231 | // }else{
232 | // [_titleView addConstraint:NSLayoutAttributeHeight equalTo:nil offset:0];
233 | // }
234 |
235 | //message设置
236 | _messageContainerView = [UIView new];
237 | _messageContainerView.backgroundColor = [UIColor whiteColor];
238 | [_upperView addSubview:_messageContainerView];
239 |
240 | [_messageContainerView addConstraint:NSLayoutAttributeLeft equalTo:_upperView offset:0];
241 | [_messageContainerView addConstraint:NSLayoutAttributeRight equalTo:_upperView offset:0];
242 | [_messageContainerView addConstraint:NSLayoutAttributeTop equalTo:_titleView toAttribute:NSLayoutAttributeBottom offset:0];
243 | [_messageContainerView addSubview:self.messageLabel];
244 |
245 | [self.messageLabel addConstraint:NSLayoutAttributeLeft equalTo:_messageContainerView offset:10];
246 | [self.messageLabel addConstraint:NSLayoutAttributeRight equalTo:_messageContainerView offset:-10];
247 | [self.messageLabel addConstraint:NSLayoutAttributeTop equalTo:_messageContainerView offset:0];
248 |
249 | UIView *lineMsg = [UIView new];
250 | lineMsg.backgroundColor = DefaultLineTranslucenceColor;
251 | [_messageContainerView addSubview:lineMsg];
252 | [_bodyLineList addObject:lineMsg];
253 |
254 | [lineMsg addConstraint:NSLayoutAttributeLeft equalTo:_messageContainerView offset:0];
255 | [lineMsg addConstraint:NSLayoutAttributeRight equalTo:_messageContainerView offset:0];
256 | [lineMsg addConstraint:NSLayoutAttributeBottom equalTo:_messageContainerView offset:0];
257 | [lineMsg addConstraint:NSLayoutAttributeHeight equalTo:nil offset:1];
258 |
259 | if (message) {
260 | self.messageLabel.text = [NSString stringWithFormat:@"\r\n%@\r\n",message];
261 | }
262 | [_messageContainerView addConstraint:NSLayoutAttributeHeight equalTo:self.messageLabel offset:1];
263 |
264 |
265 | //other设置
266 | _otherContainerView = [UIView new];
267 | _otherContainerView.backgroundColor = [UIColor whiteColor];
268 | [_upperView addSubview:_otherContainerView];
269 |
270 | [_otherContainerView addConstraint:NSLayoutAttributeLeft equalTo:_upperView offset:0];
271 | [_otherContainerView addConstraint:NSLayoutAttributeRight equalTo:_upperView offset:0];
272 | [_otherContainerView addConstraint:NSLayoutAttributeTop equalTo:_messageContainerView toAttribute:NSLayoutAttributeBottom offset:0];
273 |
274 |
275 | if (otherButtonTitles.count) {
276 |
277 | [_otherContainerView addConstraint:NSLayoutAttributeHeight equalTo:nil offset:btnHeight * otherButtonTitles.count + otherButtonTitles.count - 1];
278 | [_otherContainerView layoutIfNeeded];
279 | [self createOtherButtion:otherButtonTitles width:CGRectGetWidth(_otherContainerView.frame) height:btnHeight];
280 |
281 | }else{
282 | [_otherContainerView addConstraint:NSLayoutAttributeHeight equalTo:nil offset:0];
283 |
284 | }
285 |
286 | [_upperView addConstraint:NSLayoutAttributeBottom equalTo:_otherContainerView toAttribute:NSLayoutAttributeBottom offset:0];
287 |
288 |
289 | if (cancelButtonTitle && cancelButtonTitle.length > 0) {
290 |
291 | [self.sheetView addSubview:self.cancelContainerView];
292 | [self.cancelBtn setTitle:cancelButtonTitle forState:UIControlStateNormal];
293 | [self.cancelContainerView addSubview:self.cancelBtn];
294 |
295 | [_cancelContainerView addConstraint:NSLayoutAttributeLeft equalTo:self.sheetView offset:10];
296 | [_cancelContainerView addConstraint:NSLayoutAttributeRight equalTo:self.sheetView offset:-10];
297 |
298 | [_cancelContainerView addConstraint:NSLayoutAttributeHeight equalTo:nil offset:btnHeight];
299 |
300 | [_cancelContainerView addConstraint:NSLayoutAttributeTop equalTo:_upperView toAttribute:NSLayoutAttributeBottom offset:10];
301 |
302 | [_cancelBtn addConstraint:NSLayoutAttributeLeft equalTo:self.cancelContainerView offset:0];
303 | [_cancelBtn addConstraint:NSLayoutAttributeRight equalTo:self.cancelContainerView offset:0];
304 | [_cancelBtn addConstraint:NSLayoutAttributeTop equalTo:self.cancelContainerView offset:0];
305 | [_cancelBtn addConstraint:NSLayoutAttributeBottom equalTo:self.cancelContainerView offset:0];
306 |
307 | _bottomValue = 10;
308 | }
309 |
310 | _bottomValue += kDevice_TABBARBOTTOM;
311 |
312 |
313 | }
314 |
315 | - (void)setSheetFrame{
316 |
317 | CGFloat heigth = CGRectGetHeight(self.titleView.frame) + CGRectGetHeight(self.messageContainerView.frame) + CGRectGetHeight(self.otherContainerView.frame) + CGRectGetHeight(self.cancelContainerView.frame) + 10 + _bottomValue;
318 |
319 | CGRect rect = self.sheetView.frame;
320 | rect.size.height = heigth;
321 | self.sheetView.frame = rect;
322 | _isNeedLayout = 2;
323 | }
324 |
325 | - (void)createOtherButtion:(NSArray *)otherButtonTitles
326 | width:(CGFloat)width
327 | height:(CGFloat)height{
328 | int i = 0;
329 | for (NSString *titles in otherButtonTitles) {
330 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
331 | btn.frame = CGRectMake(0, i * (height + 1), width, height);
332 | btn.autoresizingMask = UIViewAutoresizingFlexibleWidth;
333 | btn.tag = 101 + i;
334 | btn.titleLabel.font = [UIFont systemFontOfSize:14];
335 | [btn setTitle:titles forState:UIControlStateNormal];
336 | btn.backgroundColor = [UIColor whiteColor];
337 | [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
338 | [btn addTarget:self action:@selector(buttionClick:) forControlEvents:UIControlEventTouchUpInside];
339 | [_otherContainerView addSubview:btn];
340 | [_buttionList addObject:btn];
341 | if (i != otherButtonTitles.count - 1) {
342 | UIView *lineTop = [UIView new];
343 | lineTop.frame = CGRectMake(0, CGRectGetMaxY(btn.frame), width, 1);
344 | lineTop.autoresizingMask = UIViewAutoresizingFlexibleWidth;
345 | lineTop.backgroundColor = DefaultLineTranslucenceColor;
346 | [_otherContainerView addSubview:lineTop];
347 | [_lineList addObject:lineTop];
348 | }
349 |
350 | i ++;
351 | }
352 |
353 | }
354 |
355 |
356 | //MARK: ---------------------- 配置信息 ------------------------------------
357 | - (void)setMessageFontWithName:(NSString *)name size:(CGFloat)size{
358 | if (name) {
359 | _messageLabel.font = [UIFont fontWithName:name size:size];
360 | }else{
361 | _messageLabel.font = [UIFont systemFontOfSize:size];
362 | }
363 | }
364 | - (void)setTitleFontWithName:(NSString *)name size:(CGFloat)size{
365 | if (name) {
366 | _titleLabel.font = [UIFont fontWithName:name size:size];
367 | }else{
368 | _titleLabel.font = [UIFont systemFontOfSize:size];
369 | }
370 | }
371 | - (void)hiddenBodyLineView{
372 |
373 | for (UIView *line in _bodyLineList) {
374 | line.hidden = YES;
375 | }
376 | }
377 | - (void)hiddenAllLineView{
378 | for (UIView *line in _lineList) {
379 | line.hidden = YES;
380 | }
381 | [self hiddenBodyLineView];
382 | }
383 |
384 | - (void)setAlertViewBackgroundColor:(UIColor *)color{
385 | if (_upperView) {
386 | _upperView.backgroundColor = color;
387 | }
388 | }
389 | - (void)setTitleViewBackColor:(UIColor *)color{
390 | _titleView.backgroundColor = color;
391 | }
392 | - (void)setTitleViewTitleColor:(UIColor *)color{
393 | _titleLabel.textColor = color;
394 | }
395 | - (void)setMessageTitleColor:(UIColor *)color{
396 | _messageLabel.textColor = color;
397 | }
398 | - (void)setAllButtionTitleColor:(UIColor *)color{
399 |
400 | for (UIButton *btn in _buttionList) {
401 | [btn setTitleColor:color forState:UIControlStateNormal];
402 | }
403 | }
404 | - (void)setButtionTitleColor:(UIColor *)color index:(NSInteger)index{
405 | if (index == 0) {
406 | [_cancelBtn setTitleColor:color forState:index];
407 | }else{
408 | UIButton *btn = [_otherContainerView viewWithTag:101+index];
409 | [btn setTitleColor:color forState:index];
410 | }
411 | }
412 | - (void)setButtionTitleFontWithName:(NSString *)name
413 | size:(CGFloat)size
414 | index:(NSInteger)index{
415 |
416 | if (name) {
417 | if (index == 0) {
418 | _cancelBtn.titleLabel.font = [UIFont fontWithName:name size:size];
419 | }else{
420 | UIButton *btn = [_otherContainerView viewWithTag:101+index];
421 | btn.titleLabel.font = [UIFont fontWithName:name size:size];
422 | }
423 | }else{
424 | if (index == 0) {
425 | _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:size];
426 | }else{
427 | UIButton *btn = [_otherContainerView viewWithTag:101+index];
428 | btn.titleLabel.font = [UIFont systemFontOfSize:size];
429 | }
430 | }
431 | }
432 |
433 | /**
434 | 设置蒙版的背景图
435 |
436 | @param image 蒙版的背景图(可使用高斯的image)
437 | */
438 | - (void)setGaussianBlurImage:(UIImage *)image{
439 | self.gaussianBlurOnMaskView.hidden = NO;
440 | self.gaussianBlurOnMaskView.image = image;
441 | }
442 |
443 | /**
444 | 修改tiele
445 |
446 | @param title 提示名称
447 | */
448 | - (void)resetAlertTitle:(NSString *)title{
449 | if (title) {
450 | self.titleLabel.text = [NSString stringWithFormat:@"\r\n%@\r\n",title];
451 | }else{
452 | self.titleLabel.text = nil;
453 | }
454 | if (_isNeedLayout == 2) {
455 | _isNeedLayout = 1;
456 | }
457 | }
458 | /**
459 | 修改message信息,高度也会跟着适配
460 |
461 | @param message 信息
462 | */
463 | - (void)resetAlertMessage:(NSString *)message{
464 | if (message) {
465 | self.messageLabel.text = [NSString stringWithFormat:@"\r\n%@\r\n",message];
466 | }else{
467 | self.messageLabel.text = nil;
468 | }
469 | if (_isNeedLayout == 2) {
470 | _isNeedLayout = 1;
471 | }
472 | }
473 | /**
474 | 统一配置信息
475 |
476 | @param theme 主题
477 | */
478 | - (void)setTheme:(id)theme{
479 |
480 | if ([theme respondsToSelector:@selector(alertBackgroundView)]) {
481 | NSLog(@"***********暂时不支持");
482 | }
483 | if ([theme respondsToSelector:@selector(alterBackgroundViewArticulation)]) {
484 | NSLog(@"***********暂时不支持");
485 | }
486 | if ([theme respondsToSelector:@selector(alertBackgroundColor)]) {
487 | [self setAlertViewBackgroundColor:[theme alertBackgroundColor]];
488 | }
489 | if ([theme respondsToSelector:@selector(alertTitleViewColor)]) {
490 | [self setTitleViewBackColor:[theme alertTitleViewColor]];
491 | }
492 | if ([theme respondsToSelector:@selector(alertCancelColor)]) {
493 | UIColor *color = [theme alertCancelColor];
494 | _cancelBtn.backgroundColor = color;
495 | }
496 |
497 | CGFloat alp1 = 16;
498 | if ([theme respondsToSelector:@selector(alertTitleFont)]) {
499 | alp1 = [theme alertTitleFont];
500 | }
501 | if ([theme respondsToSelector:@selector(alertTitleFontWithName)]) {
502 | [self setTitleFontWithName:[theme alertTitleFontWithName] size:alp1];
503 | }else{
504 | [self setTitleFontWithName:nil size:alp1];
505 | }
506 | CGFloat alp2 = 14;
507 | if ([theme respondsToSelector:@selector(alertMessageFont)]) {
508 | alp2 = [theme alertMessageFont];
509 | }
510 | if ([theme respondsToSelector:@selector(alertMessageFontWithName)]) {
511 | [self setMessageFontWithName:[theme alertMessageFontWithName] size:alp2];
512 | }else{
513 | [self setMessageFontWithName:nil size:alp2];
514 | }
515 |
516 | }
517 | //MARK: ----------------------------- getter & setter ----------------------------------
518 | - (UIView *)cancelContainerView{
519 | if (!_cancelContainerView) {
520 | _cancelContainerView = [UIView new];
521 | }
522 | return _cancelContainerView;
523 | }
524 | - (UIButton *)cancelBtn{
525 | if (!_cancelBtn) {
526 | _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
527 | _cancelBtn.tag = 100;
528 | _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
529 | _cancelBtn.backgroundColor = [UIColor whiteColor];
530 | [_cancelBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
531 | [_cancelBtn addTarget:self action:@selector(buttionClick:) forControlEvents:UIControlEventTouchUpInside];
532 | _cancelBtn.layer.cornerRadius = 10;
533 | _cancelBtn.layer.masksToBounds = YES;
534 | }
535 | return _cancelBtn;
536 | }
537 | - (UIView *)maskView{
538 | if (!_maskView) {
539 | _maskView = [[UIView alloc] initWithFrame:CGRectZero];
540 | _maskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
541 | _maskView.backgroundColor = [UIColor colorWithRed:10 / 255.0 green:10 / 255.0 blue:10 / 255.0 alpha:0.5];
542 | }
543 | return _maskView;
544 | }
545 | - (UIImageView *)gaussianBlurOnMaskView{
546 | if (!_gaussianBlurOnMaskView) {
547 | _gaussianBlurOnMaskView = [UIImageView new];
548 | _gaussianBlurOnMaskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
549 | _gaussianBlurOnMaskView.hidden = YES;
550 | }
551 | return _gaussianBlurOnMaskView;
552 | }
553 | - (UILabel *)titleLabel{
554 | if (!_titleLabel) {
555 | _titleLabel = [UILabel new];
556 | _titleLabel.textAlignment = NSTextAlignmentCenter;
557 | [_titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
558 | _titleLabel.numberOfLines = 0;
559 | _titleLabel.font = [UIFont systemFontOfSize:16];
560 | }
561 | return _titleLabel;
562 | }
563 | - (UILabel *)messageLabel{
564 | if (!_messageLabel) {
565 | _messageLabel = [UILabel new];
566 | [_messageLabel setLineBreakMode:NSLineBreakByWordWrapping];
567 | _messageLabel.textAlignment = NSTextAlignmentCenter;
568 | _messageLabel.numberOfLines = 0;
569 | _messageLabel.font = [UIFont systemFontOfSize:14];
570 | }
571 | return _messageLabel;
572 | }
573 |
574 | - (void)layoutIfNeeded{
575 | [super layoutIfNeeded];
576 | [self setSheetFrame];
577 | }
578 | - (void)dealloc{
579 | NSLog(@"%s",__func__);
580 | _sheetView = nil;
581 | _maskView = nil;
582 | _gaussianBlurOnMaskView = nil;
583 | _titleView = nil;
584 | _titleLabel = nil;
585 | _messageContainerView = nil;
586 | _messageLabel = nil;
587 | _otherContainerView = nil;
588 | _cancelContainerView = nil;
589 | _cancelBtn = nil;
590 | _buttionList = nil;
591 | _lineList = nil;
592 | _bodyLineList = nil;
593 | _backgroundAlterView = nil;
594 | _backgroundColor = nil;
595 | _upperView = nil;
596 |
597 |
598 | }
599 | @end
600 |
--------------------------------------------------------------------------------