瀏覽代碼

Modify Library AHKActionSheet

Marino Faggiana 8 年之前
父節點
當前提交
3716883a80

+ 0 - 1
Libraries external/AHKActionSheet/AHKActionSheet.h

@@ -42,7 +42,6 @@ typedef void(^AHKActionSheetHandler)(AHKActionSheet *actionSheet);
  *  It's best to use a color similar (but maybe with a lower alpha value) to blurTintColor.
  *  See "Advanced" example in the example project to see it used.
  */
-@property (strong, nonatomic) UIColor *cancelButtonShadowColor UI_APPEARANCE_SELECTOR;
 /// Boxed (@YES, @NO) boolean value (enabled by default). Isn't supported on iOS 6.
 @property (strong, nonatomic) NSNumber *automaticallyTintButtonImages UI_APPEARANCE_SELECTOR;
 /// Boxed boolean value. Useful when adding buttons without images (in that case text looks better centered). Disabled by default.

+ 56 - 44
Libraries external/AHKActionSheet/AHKActionSheet.m

@@ -25,7 +25,7 @@ static const CGFloat kFlickDownMinVelocity = 2000.0f;
 // How much free space to leave at the top (above the tableView's contents) when there's a lot of elements. It makes this control look similar to the UIActionSheet.
 static const CGFloat kTopSpaceMarginFraction = 0.0f;
 // cancelButton's shadow height as the ratio to the cancelButton's height
-static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
+static const CGFloat kSpaceDivide = 5.0f;
 
 
 /// Used for storing button configuration.
@@ -81,7 +81,7 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
                                                       NSForegroundColorAttributeName : [UIColor redColor] }];
     [appearance setTitleTextAttributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:14.0f],
                                           NSForegroundColorAttributeName : [UIColor grayColor] }];
-    [appearance setCancelOnPanGestureEnabled:@(YES)];
+    [appearance setCancelOnPanGestureEnabled:@(NO)];
     [appearance setCancelOnTapEmptyAreaEnabled:@(NO)];
     [appearance setAnimationDuration:kDefaultAnimationDuration];
 }
@@ -138,7 +138,7 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
 {
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier forIndexPath:indexPath];
     
-    cell.separatorInset = UIEdgeInsetsMake(0.f, 55.f, 0.f, 0.f);
+    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     
     AHKActionSheetItem *item = self.items[(NSUInteger)indexPath.row];
 
@@ -199,27 +199,52 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
     return item.height;
 }
 
-/*
--(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
+- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
 {
-    // Remove separator inset as described here: http://stackoverflow.com/a/25877725/783960
-    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
-        [cell setSeparatorInset:UIEdgeInsetsZero];
-    }
+    AHKActionSheetItem *item = self.items[(NSUInteger)indexPath.row];
     
-    // Prevent the cell from inheriting the Table View's margin settings
-    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
-        [cell setPreservesSuperviewLayoutMargins:NO];
+    CGFloat cornerRadius = 10.f;
+    cell.backgroundColor = UIColor.clearColor;
+    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
+    CGMutablePathRef pathRef = CGPathCreateMutable();
+    CGRect bounds = CGRectInset(cell.bounds, 10, 0);
+    BOOL addLine = NO;
+    
+    if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
+        CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
+    } else if (indexPath.row == 0) {
+        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
+        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
+        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
+        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
+        addLine = YES;
+    } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
+        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
+        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
+        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
+        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
+    } else {
+        CGPathAddRect(pathRef, nil, bounds);
+        addLine = YES;
     }
     
-    // Explictly set your cell's layout margins
-    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
-        [cell setLayoutMargins:UIEdgeInsetsZero];
+    layer.path = pathRef;
+    CFRelease(pathRef);
+    layer.fillColor = item.backgroundColor.CGColor;
+    
+    if (addLine == YES) {
+        CALayer *lineLayer = [[CALayer alloc] init];
+        CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
+        lineLayer.frame = CGRectMake(CGRectGetMinX(bounds), bounds.size.height-lineHeight, bounds.size.width, lineHeight);
+        lineLayer.backgroundColor = tableView.separatorColor.CGColor;
+        [layer addSublayer:lineLayer];
     }
+    
+    UIView *testView = [[UIView alloc] initWithFrame:bounds];
+    [testView.layer insertSublayer:layer atIndex:0];
+    testView.backgroundColor = UIColor.clearColor;
+    cell.backgroundView = testView;
 }
-*/
-
-
 
 #pragma mark - UIScrollViewDelegate
 
@@ -316,17 +341,18 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
     };
 
     void(^delayedAnimations)(void) = ^(void) {
-        self.cancelButton.frame = CGRectMake(0,
-                                             CGRectGetMaxY(self.bounds) - self.cancelButtonHeight,
-                                             CGRectGetWidth(self.bounds),
-                                             self.cancelButtonHeight);
+        
+        self.cancelButton.frame = CGRectMake(10, CGRectGetMaxY(self.bounds) - self.cancelButtonHeight, CGRectGetWidth(self.bounds) - 20, self.cancelButtonHeight - kSpaceDivide);
     
+        // Corner Radius
+        self.cancelButton.layer.cornerRadius = 10;
+        self.cancelButton.clipsToBounds = YES;
+        
         // Add White color background
         self.cancelButton.backgroundColor = [UIColor whiteColor];
         
         self.tableView.transform = CGAffineTransformMakeTranslation(0, 0);
 
-
         // manual calculation of table's contentSize.height
         CGFloat tableContentHeight = 0; //[self.items count] * self.buttonHeight + CGRectGetHeight(self.tableView.tableHeaderView.frame);
         for (AHKActionSheetItem *item in self.items) {
@@ -411,7 +437,7 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
         // animate sliding down tableView and cancelButton.
         [UIView animateWithDuration:duration animations:^{
             self.blurredBackgroundView.alpha = 0.0f;
-            self.cancelButton.transform = CGAffineTransformTranslate(self.cancelButton.transform, 0, self.cancelButtonHeight);
+            self.cancelButton.transform = CGAffineTransformTranslate(self.cancelButton.transform, 0, self.cancelButtonHeight - kSpaceDivide);
             self.cancelButtonShadowView.alpha = 0.0f;
 
             // Shortest shift of position sufficient to hide all tableView contents below the bottom margin.
@@ -468,33 +494,17 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
         cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
     }
 
-    NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:self.cancelButtonTitle
-                                                                    attributes:self.cancelButtonTextAttributes];
+    NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:self.cancelButtonTitle attributes:self.cancelButtonTextAttributes];
+    
     [cancelButton setAttributedTitle:attrTitle forState:UIControlStateNormal];
     [cancelButton addTarget:self action:@selector(cancelButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
-    cancelButton.frame = CGRectMake(0,
-                                    CGRectGetMaxY(self.bounds) - self.cancelButtonHeight,
-                                    CGRectGetWidth(self.bounds),
-                                    self.cancelButtonHeight);
+        
     // move the button below the screen (ready to be animated -show)
-    cancelButton.transform = CGAffineTransformMakeTranslation(0, self.cancelButtonHeight);
+    cancelButton.transform = CGAffineTransformMakeTranslation(0, self.cancelButtonHeight - kSpaceDivide);
     cancelButton.clipsToBounds = YES;
     [self addSubview:cancelButton];
 
     self.cancelButton = cancelButton;
-
-    // add a small shadow/glow above the button
-    if (self.cancelButtonShadowColor) {
-        self.cancelButton.clipsToBounds = NO;
-        CGFloat gradientHeight = (CGFloat)round(self.cancelButtonHeight * kCancelButtonShadowHeightRatio);
-        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -gradientHeight, CGRectGetWidth(self.bounds), gradientHeight)];
-        CAGradientLayer *gradient = [CAGradientLayer layer];
-        gradient.frame = view.bounds;
-        gradient.colors = @[ (id)[UIColor colorWithWhite:0.0 alpha:0.0].CGColor, (id)[self.blurTintColor colorWithAlphaComponent:0.1f].CGColor ];
-        [view.layer insertSublayer:gradient atIndex:0];
-        [self.cancelButton addSubview:view];
-        self.cancelButtonShadowView = view;
-    }
 }
 
 - (void)setUpTableView
@@ -507,8 +517,10 @@ static const CGFloat kCancelButtonShadowHeightRatio = 0.333f;
                               CGRectGetHeight(self.bounds) - statusBarHeight - self.cancelButtonHeight);
 
     UITableView *tableView = [[UITableView alloc] initWithFrame:frame];
+    
     tableView.backgroundColor = [UIColor clearColor];
     tableView.showsVerticalScrollIndicator = NO;
+    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
 
     if (self.separatorColor) {
         tableView.separatorColor = self.separatorColor;

+ 5 - 5
iOSClient/Create/CCCreateCloud.swift

@@ -47,7 +47,7 @@ class CreateMenuAdd: NSObject {
         
         actionSheet?.buttonHeight = 50.0
         actionSheet?.cancelButtonHeight = 50.0
-        actionSheet?.separatorHeight = 30.0
+        actionSheet?.separatorHeight = 5.0
         
         actionSheet?.selectedBackgroundColor = UIColor(colorLiteralRed: 0.0/255.0, green: 130.0/255.0, blue: 201.0/255.0, alpha: 0.1)
         actionSheet?.separatorColor = UIColor(colorLiteralRed: 153.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 0.2)
@@ -90,7 +90,7 @@ class CreateMenuAdd: NSObject {
 
         actionSheet?.buttonHeight = 50.0
         actionSheet?.cancelButtonHeight = 50.0
-        actionSheet?.separatorHeight = 30.0
+        actionSheet?.separatorHeight = 5.0
         
         actionSheet?.selectedBackgroundColor = UIColor(colorLiteralRed: 0.0/255.0, green: 130.0/255.0, blue: 201.0/255.0, alpha: 0.1)
         actionSheet?.separatorColor = UIColor(colorLiteralRed: 153.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 0.2)
@@ -133,7 +133,7 @@ class CreateMenuAdd: NSObject {
 
         actionSheet?.buttonHeight = 50.0
         actionSheet?.cancelButtonHeight = 50.0
-        actionSheet?.separatorHeight = 30.0
+        actionSheet?.separatorHeight = 5.0
         
         actionSheet?.selectedBackgroundColor = UIColor(colorLiteralRed: 0.0/255.0, green: 130.0/255.0, blue: 201.0/255.0, alpha: 0.1)
         actionSheet?.separatorColor = UIColor(colorLiteralRed: 153.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 0.2)
@@ -152,7 +152,7 @@ class CreateMenuAdd: NSObject {
             appDelegate.activeMain.returnCreate(Int(returnAccountWeb))
         })
         
-        actionSheet?.addButton(withTitle: "", image: nil, backgroundColor: UIColor.white, height: 10.0, type: AHKActionSheetButtonType.disabled, handler: {(AHKActionSheet) -> Void in
+        actionSheet?.addButton(withTitle: "", image: nil, backgroundColor: UIColor(colorLiteralRed: 250.0/255.0, green: 250.0/255.0, blue: 250.0/255.0, alpha: 1), height: 10.0, type: AHKActionSheetButtonType.disabled, handler: {(AHKActionSheet) -> Void in
             print("disable")
         })
         
@@ -168,7 +168,7 @@ class CreateMenuAdd: NSObject {
             appDelegate.activeMain.returnCreate(Int(returnContoCorrente))
         })
         
-        actionSheet?.addButton(withTitle: "", image: nil, backgroundColor: UIColor.white, height: 10.0, type: AHKActionSheetButtonType.disabled, handler: {(AHKActionSheet) -> Void in
+        actionSheet?.addButton(withTitle: "", image: nil, backgroundColor: UIColor(colorLiteralRed: 250.0/255.0, green: 250.0/255.0, blue: 250.0/255.0, alpha: 1), height: 10.0, type: AHKActionSheetButtonType.disabled, handler: {(AHKActionSheet) -> Void in
             print("disable")
         })