Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
1. add custom corners
  • Loading branch information
Luo-Kuang committed Oct 17, 2019
1 parent 348dc29 commit cf8fd85
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ ZFAlertAction *cancel = [ZFAlertAction actionWithTitle:@"cancel" action:^{
```
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"ActionSheet" message:@"alertWithTitle:message:style:" style:ZFAlertControllerStyleActionSheet];
```
### Releases

1.0.1
> Add custom corner
2 changes: 1 addition & 1 deletion ZFAlertController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "ZFAlertController"
s.version = "0.1.1"
s.version = "1.0.1"
s.summary = "No short description of ZFAlertController."
s.homepage = "https://github.com/FranLucky/ZFAlertController"
s.license = { :type => "MIT"}
Expand Down
4 changes: 4 additions & 0 deletions ZFAlertController/ZFAlertController.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ typedef NS_ENUM(NSUInteger, ZFAlertControllerStyle) {
* Default 5
*/
@property(nonatomic, assign) float cornerRadius;
/**
* Default UIRectCornerAllCorners
*/
@property(nonatomic, assign) UIRectCorner roundingCorners;

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

Expand Down
11 changes: 9 additions & 2 deletions ZFAlertController/ZFAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ @interface ZFAlertController ()
@property (nonatomic, strong) UIView *lineVecView;
@property (nonatomic, strong) UIView *bottomButtonView;

@property (nonatomic, strong) CAShapeLayer *maskLayer;

@property(nonatomic, assign) float titleHeight;
@property(nonatomic, assign) float messageHeight;

Expand Down Expand Up @@ -99,6 +101,7 @@ - (instancetype)initWithTitle:(NSString * _Nullable)title message:(NSString * _N
_titleColor = ZFALERT_BLACKCLOLR;
_messageColor = ZFALERT_BLACKCLOLR;
_cornerRadius = 5;
_roundingCorners = UIRectCornerAllCorners;
_titleFont = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
_messageFont = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
_style = style;
Expand All @@ -121,10 +124,11 @@ - (instancetype)initWithTitle:(NSString * _Nullable)title message:(NSString * _N
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHiden:) name:UIKeyboardWillHideNotification object:nil];

self.maskLayer = [[CAShapeLayer alloc] init];
self.contentView = ({
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[view setBackgroundColor:self.contentBackgroundColor];
view.layer.cornerRadius = self.cornerRadius;
view.layer.mask = self.maskLayer;
view;
});

Expand Down Expand Up @@ -291,7 +295,6 @@ - (void)viewWillLayoutSubviews {
}

}

if (self.style == ZFAlertControllerStyleAlert) {
[self.contentView setFrame:CGRectMake(0, 0, NOMAL_ALERT_WIDTH, y)];
[self.contentView setCenter:self.view.center];
Expand All @@ -308,6 +311,10 @@ - (void)viewWillLayoutSubviews {
}
[self.contentView setFrame:CGRectMake(0, contentY, ZF_SCREEN_WIDTH, y)];
}

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.contentView.bounds byRoundingCorners:self.roundingCorners cornerRadii:CGSizeMake(self.cornerRadius, self.cornerRadius)];
self.maskLayer.path = maskPath.CGPath;
self.maskLayer.frame = self.contentView.bounds;
}

- (void)buttonClicked:(UIButton *)button {
Expand Down
2 changes: 2 additions & 0 deletions sample/ZFAlertController/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ - (IBAction)buttclick:(UIButton *)sender {
ZFAlertAction *cancel = [ZFAlertAction actionWithTitle:@"cancel" action:^{
NSLog(@"cancel");
}];
// alertVC.cornerRadius = 10;
// alertVC.roundingCorners = UIRectCornerTopLeft | UIRectCornerTopRight;
[alertVC addAction:ok];
[alertVC addAction:cancel];
[self presentViewController:alertVC animated:YES completion:nil];
Expand Down

0 comments on commit cf8fd85

Please sign in to comment.