Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SearchCell.m « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 40af1a35da68c5b87f3f33f1605cb6275fc3dcdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

#import "SearchCell.h"
#import "UIKitCategories.h"
#import "UIColor+MapsMeColor.h"
#import "UIFont+MapsMeFonts.h"

@interface SearchCell ()

@property (nonatomic, readwrite) UILabel * titleLabel;

@end

@implementation SearchCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  self.backgroundColor = [UIColor clearColor];
  self.selectionStyle = UITableViewCellSelectionStyleDefault;
  [self addSubview:self.separatorView];
  UIView * selectedView = [[UIView alloc] initWithFrame:self.bounds];
  selectedView.backgroundColor = [UIColor pressBackground];
  self.selectedBackgroundView = selectedView;
  [self configTitleLabel];
  return self;
}

- (void)configTitleLabel
{
  self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  self.titleLabel.backgroundColor = [UIColor clearColor];
  self.titleLabel.font = [UIFont regular16];
}

- (void)setTitle:(NSString *)title selectedRanges:(NSArray *)selectedRanges
{
  NSDictionary * selectedTitleAttributes = [self selectedTitleAttributes];
  NSDictionary * unselectedTitleAttributes = [self unselectedTitleAttributes];
  if (!title || !selectedTitleAttributes || !unselectedTitleAttributes)
  {
    self.titleLabel.text = @"";
    return;
  }
  NSMutableAttributedString * attributedTitle = [[NSMutableAttributedString alloc] initWithString:title];
  [attributedTitle addAttributes:unselectedTitleAttributes range:NSMakeRange(0, [title length])];
  for (NSValue * range in selectedRanges)
    [attributedTitle addAttributes:selectedTitleAttributes range:[range rangeValue]];
  self.titleLabel.attributedText = attributedTitle;
}

- (NSDictionary *)selectedTitleAttributes
{
  return nil;
}

- (NSDictionary *)unselectedTitleAttributes
{
  return nil;
}

- (void)layoutSubviews
{
  self.separatorView.maxY = self.height;
  self.selectedBackgroundView.frame = self.bounds;
  self.backgroundView.frame = self.bounds;
}

- (UIView *)separatorView
{
  if (!_separatorView)
  {
    _separatorView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, 1)];
    _separatorView.backgroundColor = [UIColor blackDividers];
    _separatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  }
  return _separatorView;
}

@end