Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.DS_Store
*.xcuserstate
*.xccheckout
*.xcbkptlist
*.xcscheme
*.plist
29 changes: 29 additions & 0 deletions CHSectionSelectionView.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Pod::Spec.new do |s|
s.name = "CHSectionSelectionView"
s.version = "0.5.0"
s.summary = "Easy to use and highly customizable View that displays selector controls for (e.g.) UITableView Sections."

s.description = <<-DESC
Easy to use and highly customizable View that displays selector controls for (e.g.) UITableView Sections.
This project is inspired by the iPads Address Book application.
DESC

s.homepage = "https://github.com/alexandreos/CHSectionSelectionView"
s.license = { :type => 'Apache License, Version 2.0', :text => <<-LICESNSE
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Attribution is appreciated.
LICESNSE
}

s.authors = { "Alexandre Santos" => "alexandre_o_s@yahoo.com", "Clemens Beat" => "beat84@me.com" }
s.platform = :ios, '5.0'
s.source = { :git => "https://github.com/alexandreos/CHSectionSelectionView.git", :tag => "0.5.0" }
s.source_files = 'CHSectionSelectionView/CHSectionSelectionView/*.{h,m}'
s.requires_arc = true

end
Binary file modified CHSectionSelectionView/.DS_Store
Binary file not shown.
File renamed without changes.
53 changes: 35 additions & 18 deletions ...electionView/CHSectionSelectionItemView.m → ...electionView/CHSectionSelectionItemView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,44 @@

@implementation CHSectionSelectionItemView

- (void) initializeAttributes
{
// Initialization code

_contentView = [[UIView alloc] init];
_contentView.backgroundColor = [UIColor whiteColor];
[self addSubview:_contentView];

_bgImageView = [[UIImageView alloc] init];
[_contentView addSubview:_bgImageView];

_titleLabel = [[UILabel alloc] init];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textColor = [UIColor blackColor];
_titleLabel.highlightedTextColor = [UIColor whiteColor];

_titleLabel.textAlignment = NSTextAlignmentCenter;
[_contentView addSubview:_titleLabel];
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];

if(self)
{
[self initializeAttributes];
}

return self;
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code

_contentView = [[UIView alloc] init];
_contentView.backgroundColor = [UIColor whiteColor];
[self addSubview:_contentView];

_bgImageView = [[UIImageView alloc] init];
[_contentView addSubview:_bgImageView];

_titleLabel = [[UILabel alloc] init];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textColor = [UIColor blackColor];
_titleLabel.highlightedTextColor = [UIColor whiteColor];

_titleLabel.textAlignment = UITextAlignmentCenter;
[_contentView addSubview:_titleLabel];

if (self)
{
[self initializeAttributes];
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ typedef enum {
UIView *callOut; // the current shown callout, nil if no callout is shown
}

@property (nonatomic, weak) id<CHSectionSelectionViewDataSource> dataSource;
@property (nonatomic, weak) id<CHSectionSelectionViewDelegate> delegate;
@property (nonatomic, strong) IBOutlet UIView *contentView;

@property (nonatomic, weak) IBOutlet id<CHSectionSelectionViewDataSource> dataSource;
@property (nonatomic, weak) IBOutlet id<CHSectionSelectionViewDelegate> delegate;
@property (nonatomic, assign) SectionCalloutDirection calloutDirection; // Defaults to SectionCalloutDirectionRight
@property (nonatomic, assign) BOOL showCallouts; // turning callouts of and on. defaults to YES
@property (nonatomic, assign) CGFloat fixedSectionItemHeight; // can be used to make sure an item has a fixed height, will be ignored if it is 0
Expand Down
81 changes: 56 additions & 25 deletions ...oupSelectionView/CHSectionSelectionView.m → ...ionSelectionView/CHSectionSelectionView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,38 @@ @implementation CHSectionSelectionView
//////////////////////////////////////////////////////////////////////////
#pragma mark - Initialization

- (void) _initializeAttributes
{
sectionViews = [[NSMutableArray alloc] init];

self.clipsToBounds = NO; // Needed bacause the callouts will live outside our view

// setting some default values

_calloutPadding = 0;
_fixedSectionItemHeight = 0;
_showCallouts = YES;
_calloutDirection = SectionCalloutDirectionRight;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];

if(self)
{
[self _initializeAttributes];
}

return self;
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {

sectionViews = [[NSMutableArray alloc] init];

self.clipsToBounds = NO; // Needed bacause the callouts will live outside our view

// setting some default values

_calloutPadding = 0;
_fixedSectionItemHeight = 0;
_showCallouts = YES;
_calloutDirection = SectionCalloutDirectionRight;
if (self)
{
[self _initializeAttributes];
}
return self;
}
Expand All @@ -54,6 +71,20 @@ -(void)layoutSubviews
[self layoutSections];
}

#pragma mark - Properties

- (UIView *) contentView
{
if(_contentView == nil)
{
// Only instantiate if it's not set yet
_contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[self addSubview:_contentView];
}

return _contentView;
}

//////////////////////////////////////////////////////////////////////////
#pragma mark - Public methods

Expand Down Expand Up @@ -82,10 +113,10 @@ -(void)reloadSections
if (_dataSource && [_dataSource respondsToSelector:@selector(sectionSelectionView:sectionSelectionItemViewForSection:)]) {
CHSectionSelectionItemView *sectionView = [_dataSource sectionSelectionView:self sectionSelectionItemViewForSection:section];
sectionView.section = section;
NSLog(@"fetched view");
// NSLog(@"fetched view");

[sectionViews addObject:sectionView];
[self addSubview:sectionView];
[self.contentView addSubview:sectionView];

}

Expand All @@ -101,10 +132,7 @@ -(void)reloadSections

-(void)layoutSections
{



sectionHeight = self.bounds.size.height/(CGFloat)[sectionViews count];
sectionHeight = self.contentView.bounds.size.height/(CGFloat)[sectionViews count];


if (_fixedSectionItemHeight > 0) {
Expand All @@ -114,7 +142,7 @@ -(void)layoutSections
CGFloat yOffset = 0;

for (UIView *sectionView in sectionViews) {
sectionView.frame = CGRectMake(0, yOffset, self.bounds.size.width, sectionHeight);
sectionView.frame = CGRectMake(0, yOffset, self.contentView.bounds.size.width, sectionHeight);
yOffset+=sectionHeight;
}
}
Expand Down Expand Up @@ -201,15 +229,16 @@ -(void)highlightItemAtSection:(NSInteger)section

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{


UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];


for (CHSectionSelectionItemView *sectionView in sectionViews) {

if (CGRectContainsPoint(sectionView.frame, touchPoint)) {
CGRect frame = sectionView.frame;
frame.size.width = self.frame.size.width;

if (CGRectContainsPoint(frame, touchPoint)) {

[self selectedSection:sectionView.section];
highlightedSection = sectionView.section;
Expand All @@ -219,8 +248,7 @@ -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

}

highlightedSection = -1; // nothing is highlighted

highlightedSection = -1; // nothing is highlighted
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
Expand All @@ -230,7 +258,10 @@ -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

for (CHSectionSelectionItemView *sectionView in sectionViews) {

if (CGRectContainsPoint(sectionView.frame, touchPoint)) {
CGRect frame = sectionView.frame;
frame.size.width = self.frame.size.width;

if (CGRectContainsPoint(frame, touchPoint)) {

// just highlight again if the section has changed
if (sectionView.section != highlightedSection) {
Expand Down
Loading