OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h" |
| 6 |
| 7 #include "base/mac/objc_property_releaser.h" |
| 8 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 9 |
| 10 namespace { |
| 11 NSString* const kBookmarkGrayStar = @"bookmark_gray_star_large"; |
| 12 const CGFloat kEmptyBookmarkTextSize = 16.0; |
| 13 // Offset of the image view on top of the text. |
| 14 const CGFloat kImageViewOffsetFromText = 5.0; |
| 15 } // namespace |
| 16 |
| 17 @interface BookmarkCollectionViewBackground () { |
| 18 base::mac::ObjCPropertyReleaser |
| 19 _propertyReleaser_BookmarkBookmarkCollectionViewBackground; |
| 20 } |
| 21 |
| 22 // Star image view shown on top of the label. |
| 23 @property(nonatomic, retain) UIImageView* emptyBookmarksImageView; |
| 24 // Label centered on the view showing the empty bookmarks text. |
| 25 @property(nonatomic, retain) UILabel* emptyBookmarksLabel; |
| 26 |
| 27 @end |
| 28 |
| 29 @implementation BookmarkCollectionViewBackground |
| 30 |
| 31 @synthesize emptyBookmarksImageView = _emptyBookmarksImageView; |
| 32 @synthesize emptyBookmarksLabel = _emptyBookmarksLabel; |
| 33 |
| 34 - (instancetype)initWithFrame:(CGRect)frame { |
| 35 self = [super initWithFrame:frame]; |
| 36 if (self) { |
| 37 _propertyReleaser_BookmarkBookmarkCollectionViewBackground.Init( |
| 38 self, [BookmarkCollectionViewBackground class]); |
| 39 _emptyBookmarksImageView = [self newBookmarkImageView]; |
| 40 [self addSubview:_emptyBookmarksImageView]; |
| 41 _emptyBookmarksLabel = [self newEmptyBookmarkLabel]; |
| 42 [self addSubview:_emptyBookmarksLabel]; |
| 43 } |
| 44 return self; |
| 45 } |
| 46 |
| 47 - (void)layoutSubviews { |
| 48 [super layoutSubviews]; |
| 49 _emptyBookmarksLabel.frame = [self emptyBookmarkLabelFrame]; |
| 50 _emptyBookmarksImageView.frame = [self bookmarkImageViewFrame]; |
| 51 } |
| 52 |
| 53 - (NSString*)text { |
| 54 return self.emptyBookmarksLabel.text; |
| 55 } |
| 56 |
| 57 - (void)setText:(NSString*)text { |
| 58 self.emptyBookmarksLabel.text = text; |
| 59 [self setNeedsLayout]; |
| 60 } |
| 61 |
| 62 #pragma mark - Private |
| 63 |
| 64 - (UILabel*)newEmptyBookmarkLabel { |
| 65 UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 66 label.backgroundColor = [UIColor clearColor]; |
| 67 label.font = [[MDFRobotoFontLoader sharedInstance] |
| 68 mediumFontOfSize:kEmptyBookmarkTextSize]; |
| 69 label.textColor = [UIColor colorWithWhite:0 alpha:110.0 / 255]; |
| 70 label.textAlignment = NSTextAlignmentCenter; |
| 71 return label; |
| 72 } |
| 73 |
| 74 - (UIImageView*)newBookmarkImageView { |
| 75 UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| 76 imageView.image = [UIImage imageNamed:kBookmarkGrayStar]; |
| 77 return imageView; |
| 78 } |
| 79 |
| 80 // Returns vertically centered label frame. |
| 81 - (CGRect)emptyBookmarkLabelFrame { |
| 82 const CGSize labelSizeThatFit = |
| 83 [self.emptyBookmarksLabel sizeThatFits:CGSizeZero]; |
| 84 return CGRectMake( |
| 85 0, (CGRectGetHeight(self.bounds) - labelSizeThatFit.height) / 2.0, |
| 86 CGRectGetWidth(self.bounds), labelSizeThatFit.height); |
| 87 } |
| 88 |
| 89 // Returns imageView frame above the text with kImageViewOffsetFromText from |
| 90 // text. |
| 91 - (CGRect)bookmarkImageViewFrame { |
| 92 const CGRect labelRect = [self emptyBookmarkLabelFrame]; |
| 93 const CGSize imageViewSize = self.emptyBookmarksImageView.image.size; |
| 94 return CGRectMake((CGRectGetWidth(self.bounds) - imageViewSize.width) / 2.0, |
| 95 CGRectGetMinY(labelRect) - kImageViewOffsetFromText - |
| 96 imageViewSize.height, |
| 97 imageViewSize.width, imageViewSize.height); |
| 98 } |
| 99 |
| 100 @end |
OLD | NEW |