Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ProgressView] Add support for gradient progress bar.
PiperOrigin-RevId: 310977753
- Loading branch information
1 parent
39e9475
commit 9c480c2
Showing
6 changed files
with
234 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
components/ProgressView/src/private/MDCProgressGradientView.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2020-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
/** | ||
A gradient view used for an MDCProgressView's progress bar. | ||
*/ | ||
__attribute__((objc_subclassing_restricted)) @interface MDCProgressGradientView : UIView | ||
|
||
/** | ||
An array of CGColorRef objects defining the color of each gradient stop | ||
Defaults to nil. | ||
*/ | ||
@property(nonatomic, nullable, copy) NSArray *colors; | ||
|
||
@end |
64 changes: 64 additions & 0 deletions
64
components/ProgressView/src/private/MDCProgressGradientView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2016-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MDCProgressGradientView.h" | ||
|
||
@interface MDCProgressGradientView () | ||
|
||
@property(nonatomic, readonly) CAGradientLayer *gradientLayer; | ||
|
||
@end | ||
|
||
@implementation MDCProgressGradientView | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame { | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
[self commonMDCProgressGradientViewInit]; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)initWithCoder:(NSCoder *)coder { | ||
self = [super initWithCoder:coder]; | ||
if (self) { | ||
[self commonMDCProgressGradientViewInit]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)commonMDCProgressGradientViewInit { | ||
self.gradientLayer.startPoint = CGPointMake(0.0f, 0.5f); | ||
self.gradientLayer.endPoint = CGPointMake(1.0f, 0.5f); | ||
} | ||
|
||
- (void)setColors:(NSArray *)colors { | ||
self.gradientLayer.colors = colors; | ||
} | ||
|
||
- (NSArray *)colors { | ||
return self.gradientLayer.colors; | ||
} | ||
|
||
+ (Class)layerClass { | ||
return [CAGradientLayer class]; | ||
} | ||
|
||
#pragma mark - Private Helpers | ||
|
||
- (CAGradientLayer *)gradientLayer { | ||
return (CAGradientLayer *)self.layer; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters