[iOS] beautiful cell design from "Vasily the master of design"

This commit is contained in:
Kirill Zhdanovich 2013-08-08 21:36:05 +03:00
parent b6f3ea2f06
commit 75ebb768af
5 changed files with 85 additions and 23 deletions

View file

@ -22,6 +22,8 @@
ED4F8BAD17B2E67100ADD795 /* file_handle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED4F8BAC17B2E67100ADD795 /* file_handle.cpp */; };
ED4F8BAF17B2E69600ADD795 /* posix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED4F8BAE17B2E69600ADD795 /* posix.cpp */; };
ED4F8BB117B2E6B700ADD795 /* logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED4F8BB017B2E6B700ADD795 /* logging.cpp */; };
ED64330F17B3F673000985FE /* GuideCell.m in Sources */ = {isa = PBXBuildFile; fileRef = ED64330E17B3F673000985FE /* GuideCell.m */; };
ED64331117B41534000985FE /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED64331017B41533000985FE /* CoreLocation.framework */; };
ED81954717AED762004F3803 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED81954617AED762004F3803 /* UIKit.framework */; };
ED81954917AED762004F3803 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED81954817AED762004F3803 /* Foundation.framework */; };
ED81954B17AED762004F3803 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED81954A17AED762004F3803 /* CoreGraphics.framework */; };
@ -56,6 +58,9 @@
ED4F8BAC17B2E67100ADD795 /* file_handle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = file_handle.cpp; path = ../../env/file_handle.cpp; sourceTree = "<group>"; };
ED4F8BAE17B2E69600ADD795 /* posix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = posix.cpp; path = ../../env/posix.cpp; sourceTree = "<group>"; };
ED4F8BB017B2E6B700ADD795 /* logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = logging.cpp; path = ../../env/logging.cpp; sourceTree = "<group>"; };
ED64330D17B3F672000985FE /* GuideCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GuideCell.h; sourceTree = "<group>"; };
ED64330E17B3F673000985FE /* GuideCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GuideCell.m; sourceTree = "<group>"; };
ED64331017B41533000985FE /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
ED81954317AED762004F3803 /* offlineguides.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = offlineguides.app; sourceTree = BUILT_PRODUCTS_DIR; };
ED81954617AED762004F3803 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
ED81954817AED762004F3803 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@ -87,6 +92,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
ED64331117B41534000985FE /* CoreLocation.framework in Frameworks */,
ED81954717AED762004F3803 /* UIKit.framework in Frameworks */,
ED81954917AED762004F3803 /* Foundation.framework in Frameworks */,
ED81954B17AED762004F3803 /* CoreGraphics.framework in Frameworks */,
@ -122,6 +128,7 @@
ED81953A17AED761004F3803 = {
isa = PBXGroup;
children = (
ED64331017B41533000985FE /* CoreLocation.framework */,
ED81954C17AED762004F3803 /* offlineguides */,
ED81954517AED762004F3803 /* Frameworks */,
ED81954417AED762004F3803 /* Products */,
@ -162,6 +169,8 @@
ED893F6B17B231F20074E05A /* IPadSplitVC.m */,
ED81956817AEF6B6004F3803 /* GuideVC.h */,
ED81956917AEF6B6004F3803 /* GuideVC.mm */,
ED64330D17B3F672000985FE /* GuideCell.h */,
ED64330E17B3F673000985FE /* GuideCell.m */,
);
path = offlineguides;
sourceTree = "<group>";
@ -286,6 +295,7 @@
ED4F8BAD17B2E67100ADD795 /* file_handle.cpp in Sources */,
ED4F8BAF17B2E69600ADD795 /* posix.cpp in Sources */,
ED4F8BB117B2E6B700ADD795 /* logging.cpp in Sources */,
ED64330F17B3F673000985FE /* GuideCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -1,10 +1,11 @@
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@protocol ArticleDelegate <NSObject>
-(void)selectHtmlPageUrl:(NSString *)url;
@end
@interface ArticleVC : UITableViewController <UISearchBarDelegate, UITableViewDelegate>
@interface ArticleVC : UITableViewController <UISearchBarDelegate, UITableViewDelegate, CLLocationManagerDelegate>
@property (nonatomic, assign) id <ArticleDelegate> delegate;
//uses on start of application
-(NSString *)getDefaultArticle;

View file

@ -1,5 +1,6 @@
#import "ArticleVC.h"
#import "GuideVC.h"
#import "GuideCell.h"
#import "../../storage/storage.hpp"
@ -11,9 +12,12 @@
@interface ArticleVC ()
{
Storage m_storage;
CLLocationCoordinate2D m_lastLocation;
NSDate * m_lastLocationTime;
}
@property (nonatomic, strong) UISearchBar * searchBar;
@property (nonatomic, strong) CLLocationManager * locationManager;
@end
@implementation ArticleVC
@ -35,9 +39,16 @@
[self searchBar:self.searchBar textDidChange:@""];
NSString * path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"dat" inDirectory:@"/data/"];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
self.locationManager.distanceFilter = 100;
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
m_storage.Load([path UTF8String]);
m_storage.QueryArticleInfo(string());
if ([self isValidCoordinates])
m_storage.QueryArticleInfo(string(), self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude);
else
m_storage.QueryArticleInfo(string());
[self.tableView reloadData];
}
return self;
@ -61,34 +72,34 @@
return static_cast<NSInteger>(m_storage.GetResultsCount());
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 62.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"ArticleCell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
GuideCell * cell = (GuideCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell = [[GuideCell alloc] initWithReuseIdentifier:CellIdentifier];
ArticleInfo const * info = [self infoByIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithUTF8String:info->GetTitle().c_str()];
cell.mainTitile.text = [NSString stringWithUTF8String:info->GetTitle().c_str()];
string const & thumbnail = info->GetThumbnailUrl();
size_t const pos = thumbnail.find_last_of(".");
string const imageName = thumbnail.substr(0, pos);
string const imageType = thumbnail.substr(pos + 1);
NSLog(@"%@ %@", [NSString stringWithUTF8String:imageName.c_str()], [NSString stringWithUTF8String:imageType.c_str()]);
NSString * imagePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:imageName.c_str()] ofType:[NSString stringWithUTF8String:imageType.c_str()] inDirectory:THUMBNAILSFOLDER];
cell.detailTextLabel.text = [NSString stringWithUTF8String:m_storage.FormatParentName(*info).c_str()];
cell.subTitile.text = [NSString stringWithUTF8String:m_storage.FormatParentName(*info).c_str()];
UIImage * image = [UIImage imageWithContentsOfFile:imagePath];
UIImageView * uiview = [[UIImageView alloc] initWithImage:image];
[uiview setFrame:CGRectMake(0, 0, 44, 44)];
cell.mainImage.image = image;
cell.accessoryView = uiview;
// [cell.imageView setFrame:CGRectMake(cell.imageView.frame.origin.x, cell.imageView.frame.origin.y, cell.imageView.frame.size.height, 44)];
return cell;
return (UITableViewCell *)cell;
}
- (void)viewWillAppear:(BOOL)animated
@ -122,8 +133,10 @@
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
/// @todo add lat and lon to QueryInfos
m_storage.QueryArticleInfo([searchText UTF8String]);
if ([self isValidCoordinates])
m_storage.QueryArticleInfo([searchText UTF8String], self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude);
else
m_storage.QueryArticleInfo([searchText UTF8String]);
[self.tableView reloadData];
}
@ -145,4 +158,16 @@
[sub removeFromSuperview];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[self.locationManager stopUpdatingLocation];
}
-(BOOL)isValidCoordinates
{
BOOL isValid = (self.locationManager.location != nil);
if ([self.locationManager.location.timestamp timeIntervalSinceNow] > -1500.0)
[self.locationManager startUpdatingLocation];
return isValid;
}
@end

View file

@ -9,5 +9,9 @@
#import <UIKit/UIKit.h>
@interface GuideCell : UITableViewCell
@property (nonatomic, strong) UIImageView * mainImage;
@property (nonatomic, strong) UILabel * mainTitile;
@property (nonatomic, strong) UILabel * subTitile;
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier;
@end

View file

@ -10,20 +10,42 @@
@implementation GuideCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
if (self)
{
_mainImage = [[UIImageView alloc] init];
_mainTitile = [[UILabel alloc] init];
_subTitile = [[UILabel alloc] init];
self.mainTitile.backgroundColor = [UIColor clearColor];
self.mainTitile.font = [UIFont fontWithName:@"Helvetica-Regular" size:25];
self.subTitile.backgroundColor = [UIColor clearColor];
self.subTitile.font = [UIFont fontWithName:@"Helvetica-Light" size:13];
self.subTitile.textColor = [UIColor colorWithRed:51.f/255.f
green:51.f/255.f
blue:51.f/255.f
alpha:1.f];
[self.contentView addSubview:self.mainImage];
[self.contentView addSubview:self.mainTitile];
[self.contentView addSubview:self.subTitile];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
double padding = 6 + 50 + 12;
[self.mainImage setFrame:CGRectMake(6, 6, 50, 50)];
[self.mainTitile setFrame:CGRectMake(padding, 8, self.frame.size.width - padding, 25)];
[self.subTitile setFrame:CGRectMake(padding, 30, self.frame.size.width - padding, 22)];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end