Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
1. Custom space
  • Loading branch information
Luo-Kuang committed Oct 16, 2019
1 parent f8ed9af commit 348dc29
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 45 deletions.
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
### 一款高度定制化AlertView弹窗
> 使用方法和UIAlertView一样,详见sample
### - Usage
ZFAlertController is a Highly customizable AlertController for iOS.
Choose ZFAlertController for your next project, or migrate over your existing projects—you'll be happy you did!

### Installation with CocoaPods
##### Podfile
To integrate ZFAlertController into your Xcode project using CocoaPods, specify it in your Podfile:
```
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'TargetName' do
pod 'ZFAlertController', '~> 0.1.1'
end
```
Then, run the following command:
```
pod 'ZFAlertController'
pod install --repo-update
```

### Usage
All the usages are equal with UIAlertController
#### ZFAlertControllerStyleAlert
```
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"ZFAlertController" message:@"alertWithTitle:message:style:" style:ZFAlertControllerStyleAlert];
ZFAlertAction *ok = [ZFAlertAction actionWithTitle:@"ok" action:^{
NSLog(@"ok");
[self testFunc];
}];
ZFAlertAction *cancel = [ZFAlertAction actionWithTitle:@"cancel" action:^{
NSLog(@"cancel");
}];
[alertVC addAction:ok];
[alertVC addAction:cancel];
[self presentViewController:alertVC animated:YES completion:nil];
```
#### ZFAlertControllerStyleActionSheet
```
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"ActionSheet" message:@"alertWithTitle:message:style:" style:ZFAlertControllerStyleActionSheet];
```
6 changes: 3 additions & 3 deletions ZFAlertController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

Pod::Spec.new do |s|
s.name = "ZFAlertController"
s.version = "0.1.0"
s.version = "0.1.1"
s.summary = "No short description of ZFAlertController."
s.homepage = "https://github.com/FranLucky/ZFAlertController"
s.license = { :type => "MIT"}
s.author = { "Pokeey" => "[email protected]" }
s.platform = :ios, "9.0"
s.ios.deployment_target = "9.0"
s.platform = :ios, "8.0"
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/FranLucky/ZFAlertController.git", :tag => "#{s.version}" }
s.source_files = "ZFAlertController/*.{h,m}"
s.frameworks = "Foundation","UIKit"
Expand Down
96 changes: 78 additions & 18 deletions ZFAlertController/ZFAlertController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ NS_ASSUME_NONNULL_BEGIN


#define ZFALERT_BLACKCLOLR [UIColor colorWithRed:19/255.0 green:19/255.0 blue:54/255.0 alpha:1]

#define ZFALERT_OK_CLOLR [UIColor colorWithRed:0 green:180/255.0 blue:175/255.0 alpha:1]
#define ZFALERT_LINE_COLOR [UIColor colorWithRed:240/255.0 green:240/255.0 blue:243/255.0 alpha:1.0]

Expand All @@ -23,12 +22,28 @@ typedef void(^zf_TextFieldTextChanged)(NSString *text, UITextField *textField);
+ (instancetype)actionWithTitle:(NSString *)title action:(void (^ _Nullable)(void))action;

@property(nonatomic, copy) NSString *titleText;
@property (nonatomic, strong) UIFont *titleFont; // Default [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
@property (nonatomic, strong) UIColor *titleColor; // Default red:19/255.0 green:19/255.0 blue:54/255.0 alpha:1

@property(nonatomic, assign) CGFloat verticalSpaceMargin; // Only actionSheet. Default .5f
@property(nonatomic, assign) CGFloat horizontalSpaceMargin; // Only actionSheet. Default 10.0f
@property (nonatomic, strong) UIColor *separatoColor; // Only actionSheet. Default ZFALERT_LINE_COLOR
/**
* Default [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
*/
@property (nonatomic, strong) UIFont *titleFont;
/**
* Default red:19/255.0 green:19/255.0 blue:54/255.0 alpha:1
*/
@property (nonatomic, strong) UIColor *titleColor;
/**
* Only actionSheet. Default .5f
* Can make a custom line between two buttons
*/
@property(nonatomic, assign) CGFloat verticalSpaceMargin;
/**
* Left & right edge inset
* Only actionSheet. Default 10.0f
*/
@property(nonatomic, assign) CGFloat horizontalSpaceMargin;
/**
* Only actionSheet. Default ZFALERT_LINE_COLOR
*/
@property (nonatomic, strong) UIColor *separatoColor;

@end

Expand All @@ -38,20 +53,65 @@ typedef NS_ENUM(NSUInteger, ZFAlertControllerStyle) {
};

@interface ZFAlertController : UIViewController

@property (nonatomic, strong) UIColor *backgroudColor; // Background cover color,default [UIColor colorWithWhite:0 alpha:.6]
@property (nonatomic, strong) UIColor *contentBackgroundColor; // Alert background color,default [UIColor whiteColor]
@property (nonatomic, strong) UIColor *titleColor; // Default red:19/255.0 green:19/255.0 blue:54/255.0 alpha:1
@property (nonatomic, strong) UIColor *messageColor; // Default red:19/255.0 green:19/255.0 blue:54/255.0 alpha:1
/**
* Background cover color,default [UIColor colorWithWhite:0 alpha:.6]
*/
@property (nonatomic, strong) UIColor *backgroudColor;
/**
* Alert background color,default [UIColor whiteColor]
*/
@property (nonatomic, strong) UIColor *contentBackgroundColor;
/**
* Default red:19/255.0 green:19/255.0 blue:54/255.0 alpha:1
*/
@property (nonatomic, strong) UIColor *titleColor;
/**
* Default red:19/255.0 green:19/255.0 blue:54/255.0 alpha:1
*/
@property (nonatomic, strong) UIColor *messageColor;

@property(nonatomic, copy) NSString *titleText;
@property(nonatomic, copy) NSString *messageText;
@property (nonatomic, strong) UIFont *titleFont; // Default [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
@property (nonatomic, strong) UIFont *messageFont; // Default [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];

@property(nonatomic, assign) float cornerRadius; // Default 5

@property(nonatomic, assign) BOOL actionSheetIgnoreXSeriesBottomInset; // Default YES. Will not calculate safeArea bottom.
/**
* Title top margin. Default 10.
*/
@property(nonatomic, assign) float titleSpace;
/**
* Message title margin. Default 10.
*/
@property(nonatomic, assign) float messageSpace;
/**
* textField message margin. Default 10.
*/
@property(nonatomic, assign) float textFieldSpace;
/**
* Button message margin
* Default alert 20, sheet half(10).
*
*/
@property(nonatomic, assign) float buttonsSpace;
/**
* Title label font
* Default [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
*/
@property (nonatomic, strong) UIFont *titleFont;
/**
* Default [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
*/
@property (nonatomic, strong) UIFont *messageFont;
/**
* Default 5
*/
@property(nonatomic, assign) float cornerRadius;

@property (nonatomic, strong, readonly) NSArray<ZFAlertAction *> *actions;

@property (nullable, nonatomic, readonly) NSArray<UITextField *> *textFields;

/**
* Default YES. Will never calculate safeArea bottom.
*/
@property(nonatomic, assign) BOOL actionSheetIgnoreXSeriesBottomInset;

+ (instancetype)alertWithTitle:(NSString * _Nullable)title message:(NSString * _Nullable)message style:(ZFAlertControllerStyle)style;

Expand Down
31 changes: 25 additions & 6 deletions ZFAlertController/ZFAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ @interface ZFAlertController ()
@property(nonatomic, assign) float messageHeight;

@property (nonatomic, strong) NSMutableArray *buttonsArray;
@property (nonatomic, strong) NSMutableArray *actionsArray;
@property (nonatomic, strong) NSMutableDictionary *actionCallbacks;
@property (nonatomic, strong) NSMutableArray *textFiledArray;
@property (nonatomic, strong) NSMutableDictionary *textFiledCallbacks;
Expand Down Expand Up @@ -104,7 +105,13 @@ - (instancetype)initWithTitle:(NSString * _Nullable)title message:(NSString * _N
_titleText = title;
_messageText = message;

_titleSpace = NOMAL_CONTENT_MARGIN;
_messageSpace = NOMAL_CONTENT_MARGIN;
_textFieldSpace = NOMAL_CONTENT_MARGIN;
_buttonsSpace = NOMAL_CONTENT_MARGIN * 2;

self.buttonsArray = [NSMutableArray arrayWithCapacity:10];
self.actionsArray = [NSMutableArray arrayWithCapacity:10];
self.actionCallbacks = [NSMutableDictionary dictionaryWithCapacity:10];
self.textFiledArray = [NSMutableArray arrayWithCapacity:10];
self.textFiledCallbacks = [NSMutableDictionary dictionaryWithCapacity:10];
Expand Down Expand Up @@ -206,21 +213,21 @@ - (void)viewWillLayoutSubviews {
}

if (self.titleText.length > 0) {
y += NOMAL_CONTENT_MARGIN;
y += self.titleSpace;
[self.titleLabel setFrame:CGRectMake(x, y, contentWidth, self.titleHeight)];
y += self.titleHeight;
}

if (self.messageText.length > 0) {
if (y == 0) y += NOMAL_CONTENT_MARGIN;
y += (NOMAL_CONTENT_MARGIN - 5);
if (y == 0) y += self.messageSpace;
y += (self.messageSpace - 5);
[self.messageLabel setFrame:CGRectMake(x, y, contentWidth, self.messageHeight)];
y += self.messageHeight + 5;
}

if (self.textFiledArray.count > 0) {
for (UITextField *textField in self.textFiledArray) {
y += NOMAL_CONTENT_MARGIN;
y += self.textFieldSpace;
[textField setFrame:CGRectMake(20, y, contentWidth - 20, 35)];
y += 30;
}
Expand All @@ -237,7 +244,7 @@ - (void)viewWillLayoutSubviews {
float btnH = 44;
if (self.style == ZFAlertControllerStyleAlert) {
// hor
y += NOMAL_CONTENT_MARGIN * 2;
y += self.buttonsSpace;
[self.lineHorView setFrame:CGRectMake(0, y, NOMAL_ALERT_WIDTH, 1)];
y += 1;
[self.bottomButtonView setFrame:CGRectMake(0, y, NOMAL_ALERT_WIDTH, 44)];
Expand All @@ -260,7 +267,7 @@ - (void)viewWillLayoutSubviews {
BOOL haveOtherElement = NO;
if (y > 0) {
haveOtherElement = YES;
y += NOMAL_CONTENT_MARGIN;
y += (self.buttonsSpace * .5);
}
float btnWidth = ZF_SCREEN_WIDTH;
float tempy = y;
Expand Down Expand Up @@ -310,10 +317,13 @@ - (void)buttonClicked:(UIButton *)button {
}
[self.view endEditing:YES];
[self.actionCallbacks removeAllObjects];
[self.actionsArray removeAllObjects];
[self.textFiledArray removeAllObjects];
[self dismissViewControllerAnimated:YES completion:nil];
}



- (void)changeTextFieldText:(UITextField *)tf {
if (tf.markedTextRange == nil) {
zf_TextFieldTextChanged callback = self.textFiledCallbacks[@(tf.tag)];
Expand Down Expand Up @@ -360,6 +370,7 @@ - (void)addAction:(ZFAlertAction *)action {
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomButtonView addSubview:button];
}
[self.actionsArray addObject:action];
[self.buttonsArray addObject:button];
self.actionCallbacks[@(button.tag)] = action;

Expand Down Expand Up @@ -392,6 +403,14 @@ - (UITextField *)addTextFiledWithText:(NSString *)text placeholder:(NSString *)p
return tf;
}

- (NSArray<UITextField *> *)textFields {
return _textFiledArray.copy;
}

- (NSArray<ZFAlertAction *> *)actions {
return _actionsArray.copy;
}

- (void)setContentBackgroundColor:(UIColor *)backgroundColor {
_contentBackgroundColor = backgroundColor;
[self.contentView setBackgroundColor:_contentBackgroundColor];
Expand Down
44 changes: 39 additions & 5 deletions sample/ZFAlertController/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,58 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zfX-jP-dr7">
<rect key="frame" x="181.5" y="244" width="51" height="30"/>
<state key="normal" title="ZFAlert"/>
<rect key="frame" x="116.5" y="128.5" width="54" height="30"/>
<state key="normal" title="Buttons"/>
<connections>
<action selector="buttclick:" destination="BYZ-38-t0r" eventType="touchUpInside" id="9xb-p9-6rN"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Alert:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TWo-xY-tyB">
<rect key="frame" x="45" y="133" width="41.5" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1MG-AI-R9s">
<rect key="frame" x="116.5" y="168.5" width="69" height="30"/>
<state key="normal" title="TextFields"/>
<connections>
<action selector="textFields:" destination="BYZ-38-t0r" eventType="touchUpInside" id="KbR-2E-16n"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sheet" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FYm-hD-wRB">
<rect key="frame" x="45" y="274" width="45" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0h4-EA-UOl">
<rect key="frame" x="116" y="269.5" width="54" height="30"/>
<state key="normal" title="Buttons"/>
<connections>
<action selector="sheet:" destination="BYZ-38-t0r" eventType="touchUpInside" id="tEP-M6-jjH"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="zfX-jP-dr7" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="cUc-Sh-GCR"/>
<constraint firstItem="zfX-jP-dr7" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="200" id="geb-Ay-ZsZ"/>
<constraint firstItem="1MG-AI-R9s" firstAttribute="top" secondItem="zfX-jP-dr7" secondAttribute="bottom" constant="10" id="1aV-xD-lQZ"/>
<constraint firstItem="FYm-hD-wRB" firstAttribute="leading" secondItem="TWo-xY-tyB" secondAttribute="leading" id="D6g-YC-mcm"/>
<constraint firstItem="0h4-EA-UOl" firstAttribute="centerY" secondItem="FYm-hD-wRB" secondAttribute="centerY" id="OPX-aC-oRM"/>
<constraint firstItem="TWo-xY-tyB" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="45" id="XxY-C5-Ut1"/>
<constraint firstItem="0h4-EA-UOl" firstAttribute="leading" secondItem="FYm-hD-wRB" secondAttribute="trailing" constant="26" id="aOS-bA-K3i"/>
<constraint firstItem="TWo-xY-tyB" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="89" id="jPh-pW-mHf"/>
<constraint firstItem="zfX-jP-dr7" firstAttribute="leading" secondItem="TWo-xY-tyB" secondAttribute="trailing" constant="30" id="nah-tE-tb3"/>
<constraint firstItem="zfX-jP-dr7" firstAttribute="centerY" secondItem="TWo-xY-tyB" secondAttribute="centerY" id="tuM-PP-dhc"/>
<constraint firstItem="1MG-AI-R9s" firstAttribute="leading" secondItem="zfX-jP-dr7" secondAttribute="leading" id="wuC-ub-VKL"/>
<constraint firstItem="FYm-hD-wRB" firstAttribute="top" secondItem="TWo-xY-tyB" secondAttribute="bottom" constant="120" id="xi4-sP-X3m"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-65.217391304347828" y="138.61607142857142"/>
<point key="canvasLocation" x="6" y="86"/>
</scene>
</scenes>
</document>
Loading

0 comments on commit 348dc29

Please sign in to comment.