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
12 changes: 6 additions & 6 deletions UIScrollSlidingPages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
9F2035E71706475B00438E50 /* diagmonds_@2X.png in Resources */ = {isa = PBXBuildFile; fileRef = 9F2035E41706475B00438E50 /* diagmonds_@2X.png */; };
9F2035E81706475B00438E50 /* readme.txt in Resources */ = {isa = PBXBuildFile; fileRef = 9F2035E51706475B00438E50 /* readme.txt */; };
9F2035EB170648E600438E50 /* about-tomthorpelogo.png in Resources */ = {isa = PBXBuildFile; fileRef = 9F2035EA170648E600438E50 /* about-tomthorpelogo.png */; };
9F602A67171E083F00088A9C /* TTBlackTriangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F602A66171E083F00088A9C /* TTBlackTriangle.m */; };
9F602A67171E083F00088A9C /* TTTriangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F602A66171E083F00088A9C /* TTTriangle.m */; };
9F70248A16DBF6650003B5FA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F70248916DBF6650003B5FA /* UIKit.framework */; };
9F70248C16DBF6650003B5FA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F70248B16DBF6650003B5FA /* Foundation.framework */; };
9F70248E16DBF6650003B5FA /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F70248D16DBF6650003B5FA /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -41,8 +41,8 @@
9F2035E41706475B00438E50 /* diagmonds_@2X.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "diagmonds_@2X.png"; sourceTree = "<group>"; };
9F2035E51706475B00438E50 /* readme.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = readme.txt; sourceTree = "<group>"; };
9F2035EA170648E600438E50 /* about-tomthorpelogo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "about-tomthorpelogo.png"; sourceTree = "<group>"; };
9F602A65171E083F00088A9C /* TTBlackTriangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTBlackTriangle.h; sourceTree = "<group>"; };
9F602A66171E083F00088A9C /* TTBlackTriangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTBlackTriangle.m; sourceTree = "<group>"; };
9F602A65171E083F00088A9C /* TTTriangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTTriangle.h; sourceTree = "<group>"; };
9F602A66171E083F00088A9C /* TTTriangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTTriangle.m; sourceTree = "<group>"; };
9F70248616DBF6650003B5FA /* UIScrollSlidingPages.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UIScrollSlidingPages.app; sourceTree = BUILT_PRODUCTS_DIR; };
9F70248916DBF6650003B5FA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
9F70248B16DBF6650003B5FA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -182,8 +182,8 @@
9F936B53170650EF001622D8 /* TTSlidingPageTitle.h */,
9F936B54170650EF001622D8 /* TTSlidingPageTitle.m */,
9F9B9BA7170387BE00CD45B4 /* TTSlidingPagesDataSource.h */,
9F602A65171E083F00088A9C /* TTBlackTriangle.h */,
9F602A66171E083F00088A9C /* TTBlackTriangle.m */,
9F602A65171E083F00088A9C /* TTTriangle.h */,
9F602A66171E083F00088A9C /* TTTriangle.m */,
9FFDC5CA1722EEA1002A5689 /* TTScrollViewWrapper.h */,
9FFDC5CB1722EEA1002A5689 /* TTScrollViewWrapper.m */,
37989C431852727A00A97623 /* TTSliddingPageDelegate.h */,
Expand Down Expand Up @@ -312,7 +312,7 @@
9F9B9BA117037C0B00CD45B4 /* TTScrollSlidingPagesController.m in Sources */,
9F9B9BA51703836D00CD45B4 /* TTSlidingPage.m in Sources */,
9F936B55170650EF001622D8 /* TTSlidingPageTitle.m in Sources */,
9F602A67171E083F00088A9C /* TTBlackTriangle.m in Sources */,
9F602A67171E083F00088A9C /* TTTriangle.m in Sources */,
9FFDC5CC1722EEA1002A5689 /* TTScrollViewWrapper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
5 changes: 5 additions & 0 deletions UIScrollViewSlidingPages/Demo/TTViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ - (void)viewDidLoad
self.slider.titleScrollerInActiveTextColour = [UIColor grayColor];
self.slider.titleScrollerBottomEdgeColour = [UIColor darkGrayColor];
self.slider.titleScrollerBottomEdgeHeight = 2;
self.slider.triangleType = TTTriangleTypeTop;
self.slider.titleScrollerHeight = 38;
self.slider.triangleSize = CGSizeMake(15, 8);
self.slider.trianglePosition = CGPointMake(self.view.frame.size.width/2-(self.slider.triangleSize.width/2), [UIApplication sharedApplication].statusBarFrame.size.height + self.slider.titleScrollerHeight);
self.slider.triangleBackgroundColour = [UIColor whiteColor];

//set properties to customiser the slider. Make sure you set these BEFORE you access any other properties on the slider, such as the view or the datasource. Best to do it immediately after calling the init method.
//self.slider.hideStatusBarWhenScrolling = YES;
Expand Down
15 changes: 0 additions & 15 deletions UIScrollViewSlidingPages/Source/TTBlackTriangle.h

This file was deleted.

51 changes: 0 additions & 51 deletions UIScrollViewSlidingPages/Source/TTBlackTriangle.m

This file was deleted.

16 changes: 16 additions & 0 deletions UIScrollViewSlidingPages/Source/TTScrollSlidingPagesController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#import <UIKit/UIKit.h>
#import "TTSlidingPagesDataSource.h"
#import "TTSliddingPageDelegate.h"
#import "TTTriangle.h"

@class TTScrollViewWrapper;

Expand Down Expand Up @@ -114,6 +115,21 @@
* The colour of the triangle in the top scroller. If not set, the default will be black. **/
@property (nonatomic, strong) UIColor *triangleBackgroundColour;

/** @property triangleType
* @brief You can change triangle type (it means position) Top or Bottom
* Triangle position (type). If not set, the default will be TTBlackTriangleTypeTop. **/
@property (nonatomic, assign) TTTriangleType triangleType;

/** @property triangleSize
* @brief You can change triangle size
* Triangle size. If not set, the default will be CGSize(30, 10). **/
@property (nonatomic, assign) CGSize triangleSize;

/** @property trianglePosition
* @brief You can change triangle position
* Triangle size. If not set, the default will be CGSize(30, 10). **/
@property (nonatomic, assign) CGPoint trianglePosition;

/** @property disableTopScrollerShadow
* @brief Disables the shadow effect on the top header scroller
* If set to YES the shadow effect on the top header scroller will be disabled. Default is NO. **/
Expand Down
25 changes: 19 additions & 6 deletions UIScrollViewSlidingPages/Source/TTScrollSlidingPagesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ this software and associated documentation files (the "Software"), to deal in
#import "TTSlidingPage.h"
#import "TTSlidingPageTitle.h"
#import <QuartzCore/QuartzCore.h>
#import "TTBlackTriangle.h"
#import "TTTriangle.h"
#import "TTScrollViewWrapper.h"

@interface TTScrollSlidingPagesController ()
Expand All @@ -53,7 +53,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self.titleScrollerHidden = NO;
self.titleScrollerHeight = 50;
self.titleScrollerItemWidth = 150;

self.triangleType = TTTriangleTypeTop;
self.triangleSize = CGSizeMake(30, 10);

UIImage *backgroundImage = [UIImage imageNamed:@"diagmonds.png"];
if (backgroundImage != nil){
self.titleScrollerBackgroundColour = [UIColor colorWithPatternImage:backgroundImage];
Expand Down Expand Up @@ -102,12 +104,23 @@ - (void)viewDidLoad
nextYPosition += pageDotsControlHeight;
}

TTBlackTriangle *triangle;
TTTriangle *triangle;
if (!self.titleScrollerHidden){
//add a triangle view to point to the currently selected page from the header
int triangleWidth = 30;
int triangleHeight = 10;
triangle = [[TTBlackTriangle alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-(triangleWidth/2), nextYPosition/*start at the top of the nextYPosition, but dont increment the yposition, so this means the triangle sits on top of the topscroller and cuts into it a bit*/, triangleWidth, triangleHeight) color:self.triangleBackgroundColour];
CGRect triangleFrame = CGRectZero;
// check user set triangle position
if (self.trianglePosition.x) {
triangleFrame = CGRectMake(self.trianglePosition.x, self.trianglePosition.y, self.triangleSize.width, self.triangleSize.height);
} else {
if (self.triangleType == TTTriangleTypeTop) {
/*start at the top of the nextYPosition, but dont increment the yposition, so this means the triangle sits on top of the topscroller and cuts into it a bit*/
triangleFrame = CGRectMake(self.view.frame.size.width/2-(self.triangleSize.width/2), nextYPosition, self.triangleSize.width, self.triangleSize.height);
} else if (self.triangleType == TTTriangleTypeBottom) {
triangleFrame = CGRectMake(self.view.frame.size.width/2-(self.triangleSize.width/2), nextYPosition - self.triangleSize.height, self.triangleSize.width, self.triangleSize.height);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for me, the triangle's frame Y value is incorrect, and works better with the following:

triangleFrame = CGRectMake(self.view.frame.size.width/2-(self.triangleSize.width/2), nextYPosition + self.titleScrollerHeight - self.triangleSize.height, self.triangleSize.width, self.triangleSize.height);

}
}

triangle = [[TTTriangle alloc] initWithFrame:triangleFrame color:self.triangleBackgroundColour type:self.triangleType];
triangle.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:triangle];

Expand Down
24 changes: 24 additions & 0 deletions UIScrollViewSlidingPages/Source/TTTriangle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// TTTriangle.h
// UIScrollSlidingPages
//
// Created by Thomas Thorpe on 16/04/2013.
// Copyright (c) 2013 Thomas Thorpe. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, TTTriangleType) {
TTTriangleTypeTop = 1,
TTTriangleTypeBottom = 2,
};

@interface TTTriangle : UIView

@property (nonatomic, strong, readwrite) UIColor *color;
@property (nonatomic, assign, readwrite) TTTriangleType type;

- (id)initWithFrame:(CGRect)frame color:(UIColor *)sColor;
- (id)initWithFrame:(CGRect)frame color:(UIColor *)sColor type:(TTTriangleType)type;

@end
71 changes: 71 additions & 0 deletions UIScrollViewSlidingPages/Source/TTTriangle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// TTTriangle.m
// UIScrollSlidingPages
//
// Created by Thomas Thorpe on 16/04/2013.
// Copyright (c) 2013 Thomas Thorpe. All rights reserved.
//

#import "TTTriangle.h"

@implementation TTTriangle

- (id)initWithFrame:(CGRect)frame color:(UIColor *)sColor type:(TTTriangleType)type {
self = [super initWithFrame:frame];
if (self) {
_color = sColor;
_type = type;
self.backgroundColor = [UIColor clearColor];
}
return self;
}

- (id)initWithFrame:(CGRect)frame color:(UIColor *)sColor
{
return [self initWithFrame:frame color:sColor type:TTTriangleTypeTop];
}

- (id)initWithFrame:(CGRect)frame
{
return [self initWithFrame:frame color:[UIColor whiteColor] type:TTTriangleTypeTop];
}

#pragma mark - Setters / Getters

- (void)setColor:(UIColor *)color {
_color = color;

[self setNeedsDisplay];
}

- (void)setType:(TTTriangleType)type {
_type = type;

[self setNeedsDisplay];
}

#pragma mark - Drawing

-(void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextClearRect(ctx, rect);

CGContextBeginPath(ctx);
if (_type == TTTriangleTypeTop) {
CGContextMoveToPoint (ctx, CGRectGetMinX(rect), CGRectGetMinY(rect)); // top left
CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMinY(rect)); // top right
CGContextAddLineToPoint(ctx, CGRectGetMidX(rect), CGRectGetMaxY(rect)); // mid bottom
} else if (_type == TTTriangleTypeBottom) {
CGContextMoveToPoint(ctx, CGRectGetMidX(rect), CGRectGetMinY(rect));
CGContextAddLineToPoint(ctx, CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGContextAddLineToPoint(ctx, CGRectGetMaxX(rect), CGRectGetMaxY(rect));
}
CGContextClosePath(ctx);

CGContextSetFillColorWithColor(ctx, _color.CGColor);
CGContextFillPath(ctx);
}

@end