[ios] iOS 5 compatibility

This commit is contained in:
Igor Khmurets 2014-07-17 20:21:36 +03:00 committed by Alex Zolotarev
parent d031257ff4
commit e119ef7d2f
5 changed files with 80 additions and 24 deletions

View file

@ -90,10 +90,14 @@ typedef NS_ENUM(NSUInteger, CellRow)
[nc addObserver:self selector:@selector(bookmarkCategoryDeletedNotification:) name:BOOKMARK_CATEGORY_DELETED_NOTIFICATION object:nil];
[nc addObserver:self selector:@selector(metricsChangedNotification:) name:METRICS_CHANGED_NOTIFICATION object:nil];
[self.tableView registerClass:[PlacePageInfoCell class] forCellReuseIdentifier:[PlacePageInfoCell className]];
[self.tableView registerClass:[PlacePageEditCell class] forCellReuseIdentifier:[PlacePageEditCell className]];
[self.tableView registerClass:[PlacePageShareCell class] forCellReuseIdentifier:[PlacePageShareCell className]];
[self.tableView registerClass:[PlacePageRoutingCell class] forCellReuseIdentifier:[PlacePageRoutingCell className]];
if ([self.tableView respondsToSelector:@selector(registerClass:forCellReuseIdentifier:)])
{
// only for iOS 6 and higher
[self.tableView registerClass:[PlacePageInfoCell class] forCellReuseIdentifier:[PlacePageInfoCell className]];
[self.tableView registerClass:[PlacePageEditCell class] forCellReuseIdentifier:[PlacePageEditCell className]];
[self.tableView registerClass:[PlacePageShareCell class] forCellReuseIdentifier:[PlacePageShareCell className]];
[self.tableView registerClass:[PlacePageRoutingCell class] forCellReuseIdentifier:[PlacePageRoutingCell className]];
}
CGFloat const defaultHeight = 93;
[self updateHeight:defaultHeight];
@ -192,6 +196,9 @@ typedef NS_ENUM(NSUInteger, CellRow)
if (row == CellRowCommon)
{
PlacePageInfoCell * cell = [tableView dequeueReusableCellWithIdentifier:[PlacePageInfoCell className]];
if (!cell) // only for iOS 5
cell = [[PlacePageInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[PlacePageInfoCell className]];
[cell setAddress:self.address pinPoint:[self pinPoint]];
cell.color = [ColorPickerView colorForName:[self colorName]];
cell.selectedColorView.alpha = [self isBookmark] ? 1 : 0;
@ -202,18 +209,27 @@ typedef NS_ENUM(NSUInteger, CellRow)
else if (row == CellRowSet)
{
PlacePageEditCell * cell = [tableView dequeueReusableCellWithIdentifier:[PlacePageEditCell className]];
if (!cell) // only for iOS 5
cell = [[PlacePageEditCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[PlacePageEditCell className]];
cell.titleLabel.text = self.setName;
return cell;
}
else if (row == CellRowInfo)
{
PlacePageEditCell * cell = [tableView dequeueReusableCellWithIdentifier:[PlacePageEditCell className]];
if (!cell) // only for iOS 5
cell = [[PlacePageEditCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[PlacePageEditCell className]];
cell.titleLabel.text = self.info;
return cell;
}
else if (row == CellRowShare)
{
PlacePageShareCell * cell = [tableView dequeueReusableCellWithIdentifier:[PlacePageShareCell className]];
if (!cell) // only for iOS 5
cell = [[PlacePageShareCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[PlacePageShareCell className]];
cell.delegate = self;
if ([self isMarkOfType:UserMark::API])
cell.apiAppTitle = [NSString stringWithUTF8String:GetFramework().GetApiDataHolder().GetAppTitle().c_str()];
@ -224,6 +240,9 @@ typedef NS_ENUM(NSUInteger, CellRow)
else if (row == CellRowRouting)
{
PlacePageRoutingCell * cell = [tableView dequeueReusableCellWithIdentifier:[PlacePageRoutingCell className]];
if (!cell) // only for iOS 5
cell = [[PlacePageRoutingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[PlacePageRoutingCell className]];
cell.delegate = self;
return cell;
}
@ -744,7 +763,10 @@ typedef NS_ENUM(NSUInteger, CellRow)
}
else
{
_title = [[self nonEmptyTitle:[self addressInfo].GetPinName()] capitalizedStringWithLocale:[NSLocale currentLocale]];
if ([NSString instancesRespondToSelector:@selector(capitalizedStringWithLocale:)]) // iOS 6 and higher
_title = [[self nonEmptyTitle:[self addressInfo].GetPinName()] capitalizedStringWithLocale:[NSLocale currentLocale]];
else // iOS 5
_title = [[self nonEmptyTitle:[self addressInfo].GetPinName()] capitalizedString];
}
NSString * droppedPinTitle = NSLocalizedString(@"dropped_pin", nil);
@ -1004,6 +1026,17 @@ typedef NS_ENUM(NSUInteger, CellRow)
_headerView.backgroundColor = [UIColor applicationColor];
_headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
if (SYSTEM_VERSION_IS_LESS_THAN(@"6"))
{
UIView * touchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _headerView.width - 64, _headerView.height)];
[_headerView addSubview:touchView];
[touchView addGestureRecognizer:tap];
}
else
{
[_headerView addGestureRecognizer:tap];
}
[_headerView addSubview:self.titleLabel];
[_headerView addSubview:self.typeLabel];
[_headerView addSubview:self.bookmarkButton];
@ -1020,8 +1053,6 @@ typedef NS_ENUM(NSUInteger, CellRow)
[_headerView addSubview:self.editImageView];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[_headerView addGestureRecognizer:tap];
}
return _headerView;
}

View file

@ -41,11 +41,6 @@
if ([self.textField respondsToSelector:@selector(setTintColor:)])
self.textField.tintColor = [UIColor whiteColor];
UIImageView * shadowImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"SearchBarShadow"] resizableImageWithCapInsets:UIEdgeInsetsZero]];
shadowImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
shadowImageView.minY = self.height;
[self addSubview:shadowImageView];
return self;
}

View file

@ -39,15 +39,25 @@
- (void)setTitle:(NSString *)title selectedRanges:(NSArray *)selectedRanges
{
if (!title)
title = @"";
if ([self.titleLabel respondsToSelector:@selector(setAttributedText:)])
{
// iOS 6 and higher
NSMutableAttributedString * attributedTitle = [[NSMutableAttributedString alloc] initWithString:title];
[attributedTitle addAttributes:[self unselectedTitleAttributes] range:NSMakeRange(0, [title length])];
for (NSValue * range in selectedRanges)
[attributedTitle addAttributes:[self selectedTitleAttributes] range:[range rangeValue]];
if (!title)
title = @"";
self.titleLabel.attributedText = attributedTitle;
NSMutableAttributedString * attributedTitle = [[NSMutableAttributedString alloc] initWithString:title];
[attributedTitle addAttributes:[self unselectedTitleAttributes] range:NSMakeRange(0, [title length])];
for (NSValue * range in selectedRanges)
[attributedTitle addAttributes:[self selectedTitleAttributes] range:[range rangeValue]];
self.titleLabel.attributedText = attributedTitle;
}
else
{
// iOS 5
self.titleLabel.text = title;
}
}
- (NSDictionary *)selectedTitleAttributes
@ -157,6 +167,11 @@
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.numberOfLines = 0;
_titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
if (![_titleLabel respondsToSelector:@selector(setAttributedText:)])
{
_titleLabel.font = TITLE_FONT;
_titleLabel.textColor = [UIColor whiteColor];
}
}
return _titleLabel;
}

View file

@ -141,10 +141,14 @@ __weak SearchView * selfPointer;
selfPointer = self;
needToScroll = NO;
[self.tableView registerClass:[SearchCategoryCell class] forCellReuseIdentifier:[SearchCategoryCell className]];
[self.tableView registerClass:[SearchResultCell class] forCellReuseIdentifier:[SearchResultCell className]];
[self.tableView registerClass:[SearchSuggestCell class] forCellReuseIdentifier:[SearchSuggestCell className]];
[self.tableView registerClass:[SearchShowOnMapCell class] forCellReuseIdentifier:[SearchShowOnMapCell className]];
if ([self.tableView respondsToSelector:@selector(registerClass:forCellReuseIdentifier:)])
{
// only for iOS 6 and higher
[self.tableView registerClass:[SearchCategoryCell class] forCellReuseIdentifier:[SearchCategoryCell className]];
[self.tableView registerClass:[SearchResultCell class] forCellReuseIdentifier:[SearchResultCell className]];
[self.tableView registerClass:[SearchSuggestCell class] forCellReuseIdentifier:[SearchSuggestCell className]];
[self.tableView registerClass:[SearchShowOnMapCell class] forCellReuseIdentifier:[SearchShowOnMapCell className]];
}
return self;
}
@ -480,6 +484,8 @@ static void onSearchResultCallback(search::Results const & results)
case CellTypeCategory:
{
SearchCategoryCell * customCell = [tableView dequeueReusableCellWithIdentifier:[SearchCategoryCell className]];
if (!customCell) // only for iOS 5
customCell = [[SearchCategoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[SearchCategoryCell className]];
customCell.titleLabel.text = NSLocalizedString(self.categoriesNames[indexPath.row], nil);
NSString * iconName = [NSString stringWithFormat:@"CategoryIcon%@", [self.categoriesNames[indexPath.row] capitalizedString]];
@ -490,6 +496,8 @@ static void onSearchResultCallback(search::Results const & results)
case CellTypeShowOnMap:
{
SearchShowOnMapCell * customCell = [tableView dequeueReusableCellWithIdentifier:[SearchShowOnMapCell className]];
if (!customCell) // only for iOS 5
customCell = [[SearchShowOnMapCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[SearchShowOnMapCell className]];
customCell.titleLabel.text = NSLocalizedString(@"search_on_map", nil);
cell = customCell;
@ -498,6 +506,8 @@ static void onSearchResultCallback(search::Results const & results)
case CellTypeResult:
{
SearchResultCell * customCell = [tableView dequeueReusableCellWithIdentifier:[SearchResultCell className]];
if (!customCell) // only for iOS 5
customCell = [[SearchResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[SearchResultCell className]];
NSInteger const position = [self searchResultPositionForIndexPath:indexPath];
search::Result const & result = [self.wrapper resultWithPosition:position];
@ -520,6 +530,8 @@ static void onSearchResultCallback(search::Results const & results)
case CellTypeSuggest:
{
SearchSuggestCell * customCell = [tableView dequeueReusableCellWithIdentifier:[SearchSuggestCell className]];
if (!customCell) // only for iOS 5
customCell = [[SearchSuggestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[SearchSuggestCell className]];
NSInteger const position = [self searchResultPositionForIndexPath:indexPath];
search::Result const & result = [self.wrapper resultWithPosition:position];
@ -719,7 +731,10 @@ static void onSearchResultCallback(search::Results const & results)
if (!_topBackgroundView)
{
_topBackgroundView = [[SolidTouchImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, 0)];
_topBackgroundView.image = [[UIImage imageNamed:@"SearchViewTopBackground"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 10, 0) resizingMode:UIImageResizingModeStretch];
if ([UIImage instancesRespondToSelector:@selector(resizableImageWithCapInsets:resizingMode:)]) // iOS 6 and higher
_topBackgroundView.image = [[UIImage imageNamed:@"SearchViewTopBackground"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 10, 0) resizingMode:UIImageResizingModeStretch];
else // iOS 5
_topBackgroundView.image = [[UIImage imageNamed:@"SearchViewTopBackground"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 10, 0)];
_topBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_topBackgroundView.userInteractionEnabled = YES;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB