-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Banner] Add intrinsicContentSize support with an example. (#7620)
Previously, `intrinsicContentSize` was not supported in MDCBannerView, which means users have to specify layout constraints for width and height manually. After adding `intrinsicContentSize` support, users will only need to specify width constraints for banner to show it properly. This implementation and behavior matches UITextView. Screenshot: ![Simulator Screen Shot - iPhone 7 - 2019-06-17 at 17 18 30](https://user-images.githubusercontent.com/8836258/59637507-f3b32e80-9123-11e9-8133-7108c1a7824e.png)
- Loading branch information
1 parent
cc5cce8
commit 37a495b
Showing
3 changed files
with
114 additions
and
0 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
101 changes: 101 additions & 0 deletions
101
components/Banner/examples/BannerAutolayoutExampleViewController.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,101 @@ | ||
// Copyright 2019-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> | ||
|
||
#import "MaterialBanner.h" | ||
#import "MaterialButtons+Theming.h" | ||
#import "MaterialButtons.h" | ||
#import "MaterialColorScheme.h" | ||
#import "MaterialContainerScheme.h" | ||
|
||
static NSString *const exampleText = @"Lorem ipsum dolor"; | ||
|
||
@interface BannerAutolayoutExampleViewController : UIViewController | ||
|
||
@property(nonatomic, readwrite, strong) MDCContainerScheme *containerScheme; | ||
@property(nonatomic, readwrite, strong) MDCBannerView *bannerView; | ||
|
||
@end | ||
|
||
@implementation BannerAutolayoutExampleViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
self.containerScheme = [[MDCContainerScheme alloc] init]; | ||
self.view.backgroundColor = self.containerScheme.colorScheme.backgroundColor; | ||
|
||
// Action Button | ||
MDCButton *button = [[MDCButton alloc] init]; | ||
button.translatesAutoresizingMaskIntoConstraints = NO; | ||
[button applyTextThemeWithScheme:self.containerScheme]; | ||
[button setTitle:@"Material Banner" forState:UIControlStateNormal]; | ||
[button addTarget:self | ||
action:@selector(didTapButton) | ||
forControlEvents:UIControlEventTouchUpInside]; | ||
[self.view addSubview:button]; | ||
NSLayoutConstraint *buttonConstraintCenterX = | ||
[button.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor]; | ||
buttonConstraintCenterX.active = YES; | ||
NSLayoutConstraint *buttonConstraintCenterY = | ||
[button.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor]; | ||
buttonConstraintCenterY.active = YES; | ||
|
||
// Prepare Banner | ||
MDCBannerView *bannerView = [[MDCBannerView alloc] init]; | ||
bannerView.translatesAutoresizingMaskIntoConstraints = NO; | ||
bannerView.textLabel.text = exampleText; | ||
bannerView.trailingButton.hidden = YES; | ||
bannerView.showsDivider = YES; | ||
bannerView.layoutMargins = UIEdgeInsetsZero; | ||
MDCButton *actionButton = bannerView.leadingButton; | ||
[actionButton applyTextThemeWithScheme:self.containerScheme]; | ||
[actionButton setTitle:@"Dismiss" forState:UIControlStateNormal]; | ||
[actionButton addTarget:self | ||
action:@selector(didTapDismissOnBannerView) | ||
forControlEvents:UIControlEventTouchUpInside]; | ||
[self.view addSubview:bannerView]; | ||
NSLayoutConstraint *bannerViewConstraintTop = | ||
[bannerView.topAnchor constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor]; | ||
bannerViewConstraintTop.active = YES; | ||
NSLayoutConstraint *bannerViewConstraintLeft = | ||
[bannerView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor]; | ||
bannerViewConstraintLeft.active = YES; | ||
NSLayoutConstraint *bannerViewConstraintRight = | ||
[bannerView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor]; | ||
bannerViewConstraintRight.active = YES; | ||
bannerView.hidden = YES; | ||
self.bannerView = bannerView; | ||
} | ||
|
||
- (void)didTapButton { | ||
self.bannerView.hidden = NO; | ||
} | ||
|
||
- (void)didTapDismissOnBannerView { | ||
self.bannerView.hidden = YES; | ||
} | ||
|
||
#pragma mark - CBC | ||
|
||
+ (NSDictionary *)catalogMetadata { | ||
return @{ | ||
@"breadcrumbs" : @[ @"Banner", @"Banner (Autolayout)" ], | ||
@"primaryDemo" : @NO, | ||
@"presentable" : @YES, | ||
}; | ||
} | ||
|
||
@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