Skip to content

Commit

Permalink
Refactor orientation property
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Rivera committed Aug 20, 2014
1 parent 6059502 commit 3821ec9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Classes/EasyTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#define ROTATED_CELL_VIEW_TAG 801
#define CELL_CONTENT_TAG 802

typedef enum {
EasyTableViewOrientationVertical,
typedef NS_ENUM(NSUInteger, EasyTableViewOrientation){
EasyTableViewOrientationVertical,
EasyTableViewOrientationHorizontal
} EasyTableViewOrientation;
};

@class EasyTableView;

Expand All @@ -66,7 +66,7 @@ typedef enum {
@property (nonatomic, readonly, weak) NSArray *visibleViews;
@property (nonatomic) NSIndexPath *selectedIndexPath;
@property (nonatomic) UIColor *cellBackgroundColor;
@property (nonatomic, readonly) EasyTableViewOrientation orientation;
@property (nonatomic) EasyTableViewOrientation orientation;
@property (nonatomic, assign) CGPoint contentOffset;
@property (nonatomic, assign) NSUInteger numberOfCells;

Expand Down
26 changes: 17 additions & 9 deletions Classes/EasyTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ - (id)initWithFrame:(CGRect)frame numberOfColumns:(NSUInteger)numCols ofWidth:(C
if (self = [super initWithFrame:frame]) {
_numItems = numCols;
_cellWidthOrHeight = width;
_orientation = EasyTableViewOrientationHorizontal;
self.orientation = EasyTableViewOrientationHorizontal;
self.tableView = [UITableView new];
}
return self;
Expand All @@ -51,7 +51,7 @@ - (id)initWithFrame:(CGRect)frame numberOfRows:(NSUInteger)numRows ofHeight:(CGF
if (self = [super initWithFrame:frame]) {
_numItems = numRows;
_cellWidthOrHeight = height;
_orientation = EasyTableViewOrientationVertical;
self.orientation = EasyTableViewOrientationVertical;
self.tableView = [UITableView new];
}
return self;
Expand All @@ -63,20 +63,28 @@ - (void)setTableView:(UITableView *)tableView
{
_tableView = tableView;

self.orientation = _orientation;

_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_tableView];
}

- (void)setOrientation:(EasyTableViewOrientation)orientation
{
_orientation = orientation;

if (_orientation == EasyTableViewOrientationHorizontal) {
int xOrigin = (self.bounds.size.width - self.bounds.size.height)/2;
int yOrigin = (self.bounds.size.height - self.bounds.size.width)/2;
_tableView.frame = CGRectMake(xOrigin, yOrigin, self.bounds.size.height, self.bounds.size.width);
_tableView.transform = CGAffineTransformMakeRotation(-M_PI/2);
self.tableView.frame = CGRectMake(xOrigin, yOrigin, self.bounds.size.height, self.bounds.size.width);
self.tableView.transform = CGAffineTransformMakeRotation(-M_PI/2);
}
else
{
_tableView.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
self.tableView.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
}
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_tableView];
}

- (NSArray *)visibleViews {
Expand Down

0 comments on commit 3821ec9

Please sign in to comment.