|
18 | 18 | #import <MDFInternationalization/MDFInternationalization.h>
|
19 | 19 |
|
20 | 20 | #import "MDCChipFieldDelegate.h"
|
| 21 | +#import "MDCChipViewDeleteButton.h" |
21 | 22 | #import "MaterialTextFields.h"
|
22 | 23 |
|
23 | 24 | NSString *const MDCEmptyTextString = @"";
|
|
28 | 29 | static const CGFloat MDCChipFieldIndent = 4;
|
29 | 30 | static const CGFloat MDCChipFieldHorizontalMargin = 8;
|
30 | 31 | static const CGFloat MDCChipFieldVerticalMargin = 8;
|
31 |
| -static const CGFloat MDCChipFieldClearButtonSquareWidthHeight = 24; |
32 |
| -static const CGFloat MDCChipFieldClearImageSquareWidthHeight = 18; |
33 | 32 | static const UIKeyboardType MDCChipFieldDefaultKeyboardType = UIKeyboardTypeEmailAddress;
|
34 | 33 |
|
35 | 34 | const CGFloat MDCChipFieldDefaultMinTextFieldWidth = 44;
|
@@ -377,147 +376,13 @@ - (void)createNewChipFromInput {
|
377 | 376 | }
|
378 | 377 |
|
379 | 378 | - (void)addClearButtonToChip:(MDCChipView *)chip {
|
380 |
| - UIControl *clearButton = [[UIControl alloc] init]; |
381 |
| - CGFloat clearButtonWidthAndHeight = MDCChipFieldClearButtonSquareWidthHeight; |
382 |
| - clearButton.frame = CGRectMake(0, 0, clearButtonWidthAndHeight, clearButtonWidthAndHeight); |
383 |
| - clearButton.layer.cornerRadius = clearButtonWidthAndHeight / 2; |
384 |
| - UIImageView *clearImageView = [[UIImageView alloc] initWithImage:[self drawClearButton]]; |
385 |
| - CGFloat widthAndHeight = MDCChipFieldClearImageSquareWidthHeight; |
386 |
| - CGFloat padding = |
387 |
| - (MDCChipFieldClearButtonSquareWidthHeight - MDCChipFieldClearImageSquareWidthHeight) / 2; |
388 |
| - clearImageView.frame = CGRectMake(padding, padding, widthAndHeight, widthAndHeight); |
389 |
| - clearButton.tintColor = [UIColor.blackColor colorWithAlphaComponent:(CGFloat)0.6]; |
390 |
| - [clearButton addSubview:clearImageView]; |
| 379 | + MDCChipViewDeleteButton *clearButton = [[MDCChipViewDeleteButton alloc] init]; |
391 | 380 | chip.accessoryView = clearButton;
|
392 | 381 | [clearButton addTarget:self
|
393 | 382 | action:@selector(deleteChip:)
|
394 | 383 | forControlEvents:UIControlEventTouchUpInside];
|
395 | 384 | }
|
396 | 385 |
|
397 |
| -- (UIImage *)drawClearButton { |
398 |
| - CGSize clearButtonSize = |
399 |
| - CGSizeMake(MDCChipFieldClearImageSquareWidthHeight, MDCChipFieldClearImageSquareWidthHeight); |
400 |
| - |
401 |
| - CGRect bounds = CGRectMake(0, 0, clearButtonSize.width, clearButtonSize.height); |
402 |
| - UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0); |
403 |
| - [UIColor.grayColor setFill]; |
404 |
| - [MDCPathForClearButtonImageFrame(bounds) fill]; |
405 |
| - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); |
406 |
| - UIGraphicsEndImageContext(); |
407 |
| - |
408 |
| - image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
409 |
| - return image; |
410 |
| -} |
411 |
| - |
412 |
| -static inline UIBezierPath *MDCPathForClearButtonImageFrame(CGRect frame) { |
413 |
| - // GENERATED CODE |
414 |
| - |
415 |
| - CGRect innerBounds = |
416 |
| - CGRectMake(CGRectGetMinX(frame) + 2, CGRectGetMinY(frame) + 2, |
417 |
| - floor((frame.size.width - 2) * (CGFloat)0.90909 + (CGFloat)0.5), |
418 |
| - floor((frame.size.height - 2) * (CGFloat)0.90909 + (CGFloat)0.5)); |
419 |
| - UIBezierPath *ic_clear_path = [UIBezierPath bezierPath]; |
420 |
| - [ic_clear_path moveToPoint:CGPointMake(CGRectGetMinX(innerBounds) + |
421 |
| - (CGFloat)0.50000 * innerBounds.size.width, |
422 |
| - CGRectGetMinY(innerBounds) + 0 * innerBounds.size.height)]; |
423 |
| - [ic_clear_path |
424 |
| - addCurveToPoint:CGPointMake( |
425 |
| - CGRectGetMinX(innerBounds) + 1 * innerBounds.size.width, |
426 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.50000 * innerBounds.size.height) |
427 |
| - controlPoint1:CGPointMake( |
428 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.77600 * innerBounds.size.width, |
429 |
| - CGRectGetMinY(innerBounds) + 0 * innerBounds.size.height) |
430 |
| - controlPoint2:CGPointMake( |
431 |
| - CGRectGetMinX(innerBounds) + 1 * innerBounds.size.width, |
432 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.22400 * innerBounds.size.height)]; |
433 |
| - [ic_clear_path |
434 |
| - addCurveToPoint:CGPointMake( |
435 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.50000 * innerBounds.size.width, |
436 |
| - CGRectGetMinY(innerBounds) + 1 * innerBounds.size.height) |
437 |
| - controlPoint1:CGPointMake( |
438 |
| - CGRectGetMinX(innerBounds) + 1 * innerBounds.size.width, |
439 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.77600 * innerBounds.size.height) |
440 |
| - controlPoint2:CGPointMake( |
441 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.77600 * innerBounds.size.width, |
442 |
| - CGRectGetMinY(innerBounds) + 1 * innerBounds.size.height)]; |
443 |
| - [ic_clear_path |
444 |
| - addCurveToPoint:CGPointMake( |
445 |
| - CGRectGetMinX(innerBounds) + 0 * innerBounds.size.width, |
446 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.50000 * innerBounds.size.height) |
447 |
| - controlPoint1:CGPointMake( |
448 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.22400 * innerBounds.size.width, |
449 |
| - CGRectGetMinY(innerBounds) + 1 * innerBounds.size.height) |
450 |
| - controlPoint2:CGPointMake( |
451 |
| - CGRectGetMinX(innerBounds) + 0 * innerBounds.size.width, |
452 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.77600 * innerBounds.size.height)]; |
453 |
| - [ic_clear_path |
454 |
| - addCurveToPoint:CGPointMake( |
455 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.50000 * innerBounds.size.width, |
456 |
| - CGRectGetMinY(innerBounds) + 0 * innerBounds.size.height) |
457 |
| - controlPoint1:CGPointMake( |
458 |
| - CGRectGetMinX(innerBounds) + 0 * innerBounds.size.width, |
459 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.22400 * innerBounds.size.height) |
460 |
| - controlPoint2:CGPointMake( |
461 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.22400 * innerBounds.size.width, |
462 |
| - CGRectGetMinY(innerBounds) + 0 * innerBounds.size.height)]; |
463 |
| - [ic_clear_path closePath]; |
464 |
| - [ic_clear_path |
465 |
| - moveToPoint:CGPointMake( |
466 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.73417 * innerBounds.size.width, |
467 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.31467 * innerBounds.size.height)]; |
468 |
| - [ic_clear_path |
469 |
| - addLineToPoint:CGPointMake( |
470 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.68700 * innerBounds.size.width, |
471 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.26750 * innerBounds.size.height)]; |
472 |
| - [ic_clear_path |
473 |
| - addLineToPoint:CGPointMake( |
474 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.50083 * innerBounds.size.width, |
475 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.45367 * innerBounds.size.height)]; |
476 |
| - [ic_clear_path |
477 |
| - addLineToPoint:CGPointMake( |
478 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.31467 * innerBounds.size.width, |
479 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.26750 * innerBounds.size.height)]; |
480 |
| - [ic_clear_path |
481 |
| - addLineToPoint:CGPointMake( |
482 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.26750 * innerBounds.size.width, |
483 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.31467 * innerBounds.size.height)]; |
484 |
| - [ic_clear_path |
485 |
| - addLineToPoint:CGPointMake( |
486 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.45367 * innerBounds.size.width, |
487 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.50083 * innerBounds.size.height)]; |
488 |
| - [ic_clear_path |
489 |
| - addLineToPoint:CGPointMake( |
490 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.26750 * innerBounds.size.width, |
491 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.68700 * innerBounds.size.height)]; |
492 |
| - [ic_clear_path |
493 |
| - addLineToPoint:CGPointMake( |
494 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.31467 * innerBounds.size.width, |
495 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.73417 * innerBounds.size.height)]; |
496 |
| - [ic_clear_path |
497 |
| - addLineToPoint:CGPointMake( |
498 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.50083 * innerBounds.size.width, |
499 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.54800 * innerBounds.size.height)]; |
500 |
| - [ic_clear_path |
501 |
| - addLineToPoint:CGPointMake( |
502 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.68700 * innerBounds.size.width, |
503 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.73417 * innerBounds.size.height)]; |
504 |
| - [ic_clear_path |
505 |
| - addLineToPoint:CGPointMake( |
506 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.73417 * innerBounds.size.width, |
507 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.68700 * innerBounds.size.height)]; |
508 |
| - [ic_clear_path |
509 |
| - addLineToPoint:CGPointMake( |
510 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.54800 * innerBounds.size.width, |
511 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.50083 * innerBounds.size.height)]; |
512 |
| - [ic_clear_path |
513 |
| - addLineToPoint:CGPointMake( |
514 |
| - CGRectGetMinX(innerBounds) + (CGFloat)0.73417 * innerBounds.size.width, |
515 |
| - CGRectGetMinY(innerBounds) + (CGFloat)0.31467 * innerBounds.size.height)]; |
516 |
| - [ic_clear_path closePath]; |
517 |
| - |
518 |
| - return ic_clear_path; |
519 |
| -} |
520 |
| - |
521 | 386 | - (void)deleteChip:(id)sender {
|
522 | 387 | UIControl *deleteButton = (UIControl *)sender;
|
523 | 388 | MDCChipView *chip = (MDCChipView *)deleteButton.superview;
|
@@ -762,7 +627,7 @@ - (CGFloat)textInputDesiredWidth {
|
762 | 627 | context:nil];
|
763 | 628 | return MAX(placeholderDesiredWidth, CGRectGetWidth(desiredRect) + MDCChipFieldHorizontalMargin +
|
764 | 629 | self.contentEdgeInsets.right +
|
765 |
| - MDCChipFieldClearImageSquareWidthHeight); |
| 630 | + [MDCChipViewDeleteButton imageSideLength]); |
766 | 631 | }
|
767 | 632 |
|
768 | 633 | - (CGFloat)placeholderDesiredWidth {
|
|
0 commit comments