Skip to content

Commit

Permalink
Migrate to ARC, remove @synthesize and ivars
Browse files Browse the repository at this point in the history
  • Loading branch information
delebedev committed Jan 26, 2013
1 parent ff4741e commit 3789418
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 175 deletions.
8 changes: 5 additions & 3 deletions BrowserTabViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
110E97A915FC25EF00F0C8DF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 110E97A815FC25EF00F0C8DF /* Foundation.framework */; };
110E97AB15FC25EF00F0C8DF /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 110E97AA15FC25EF00F0C8DF /* CoreGraphics.framework */; };
110E97B115FC25EF00F0C8DF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 110E97AF15FC25EF00F0C8DF /* InfoPlist.strings */; };
110E97B315FC25EF00F0C8DF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 110E97B215FC25EF00F0C8DF /* main.m */; };
110E97B715FC25EF00F0C8DF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 110E97B615FC25EF00F0C8DF /* AppDelegate.m */; };
110E97BA15FC25EF00F0C8DF /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 110E97B915FC25EF00F0C8DF /* ViewController.m */; };
110E97B315FC25EF00F0C8DF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 110E97B215FC25EF00F0C8DF /* main.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
110E97B715FC25EF00F0C8DF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 110E97B615FC25EF00F0C8DF /* AppDelegate.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
110E97BA15FC25EF00F0C8DF /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 110E97B915FC25EF00F0C8DF /* ViewController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
110E97BD15FC25EF00F0C8DF /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 110E97BB15FC25EF00F0C8DF /* ViewController.xib */; };
110E97C515FC25F000F0C8DF /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 110E97C415FC25F000F0C8DF /* SenTestingKit.framework */; };
110E97C615FC25F000F0C8DF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 110E97A615FC25EF00F0C8DF /* UIKit.framework */; };
Expand Down Expand Up @@ -437,6 +437,7 @@
110E97D615FC25F000F0C8DF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BrowserTabViewDemo/BrowserTabViewDemo-Prefix.pch";
INFOPLIST_FILE = "BrowserTabViewDemo/BrowserTabViewDemo-Info.plist";
Expand All @@ -449,6 +450,7 @@
110E97D715FC25F000F0C8DF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BrowserTabViewDemo/BrowserTabViewDemo-Prefix.pch";
INFOPLIST_FILE = "BrowserTabViewDemo/BrowserTabViewDemo-Info.plist";
Expand Down
60 changes: 19 additions & 41 deletions BrowserTabViewDemo/BrowserTabView/BrowserTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,24 @@

#import <UIKit/UIKit.h>
#import "BrowserTabView.h"
@class BrowserTabView;
@interface BrowserTab : UIView{
//font of tab title
UIFont *titleFont;

//color for tab title when tab been normal state
UIColor *normalTitleColor;

// image for tab been selected
UIImage *tabSelectedImage;

// image for tab been normal state
UIImage *tabNormalImage;

NSString *reuseIdentifier;
UIImageView *imageView;
UIImageView *imageViewClose;

NSInteger index;

BOOL previousSelected ;
BOOL selected;

UIPanGestureRecognizer *panGuesture;
BrowserTabView *delegate;
}
@property(nonatomic, retain) UIFont *titleFont;
@property(nonatomic, retain) NSString *title;
@property(nonatomic, assign) BOOL selected;
@property(nonatomic, retain) UIImage *tabSelectedImage;
@property(nonatomic, retain) UIImage *tabNormalImage;
@property(nonatomic, retain) UIColor *normalTitleColor;
@property(nonatomic, retain) UIColor *selectedTitleColor;
@property(nonatomic, retain) UIImageView *imageView;;
@property(nonatomic, retain) UILabel *textLabel;
@property(nonatomic, retain) UIImageView *imageViewClose;
@property(nonatomic, readonly) NSString *reuseIdentifier;
@property(nonatomic, assign) NSInteger index;
@property(nonatomic, assign) BrowserTabView * delegate;

-(id)initWithReuseIdentifier:(NSString *)aReuseIdentifier andDelegate:(id)aDelegate;
-(void)prepareForReuse;
@interface BrowserTab : UIView

@property (nonatomic, strong) UIFont *titleFont;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, assign) BOOL selected;
@property (nonatomic, strong) UIImage *tabSelectedImage;
@property (nonatomic, strong) UIImage *tabNormalImage;
@property (nonatomic, strong) UIColor *normalTitleColor;
@property (nonatomic, strong) UIColor *selectedTitleColor;
@property (nonatomic, strong) UIImageView *imageView;;
@property (nonatomic, strong) UILabel *textLabel;
@property (nonatomic, strong) UIImageView *imageViewClose;
@property (weak, nonatomic, readonly) NSString *reuseIdentifier;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, weak) BrowserTabView *delegate;

- (id)initWithReuseIdentifier:(NSString *)aReuseIdentifier andDelegate:(id)aDelegate;
- (void)prepareForReuse;

@end
91 changes: 40 additions & 51 deletions BrowserTabViewDemo/BrowserTabView/BrowserTab.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,32 @@
//

#import "BrowserTab.h"

//define width of a tab ,here is the width of the image used to render tab;

#define TAB_WIDTH 154
#define TAB_HEIGHT 38

@interface BrowserTab () {
NSString *__weak reuseIdentifier;
BOOL previousSelected;
UIPanGestureRecognizer *panGuesture;
}

@end

@implementation BrowserTab
@synthesize title;
@synthesize titleFont;
@synthesize selected=_selected;
@synthesize tabNormalImage;
@synthesize tabSelectedImage;
@synthesize normalTitleColor;
@synthesize selectedTitleColor;

@synthesize reuseIdentifier;
@synthesize imageView;
@synthesize imageViewClose;
@synthesize textLabel;
@synthesize index;
@synthesize delegate;

#pragma mark -
#pragma mark init
-(id)initWithReuseIdentifier:(NSString *)aReuseIdentifier andDelegate:(id)aDelegate
#pragma mark - init
- (id)initWithReuseIdentifier:(NSString *)aReuseIdentifier andDelegate:(id)aDelegate
{
self = [super initWithFrame:CGRectZero];
if (self) {

if (self = [super initWithFrame:CGRectZero]) {

delegate = aDelegate;
reuseIdentifier = [aReuseIdentifier retain];
_delegate = aDelegate;
reuseIdentifier = aReuseIdentifier;
self.normalTitleColor = [UIColor whiteColor];
self.selectedTitleColor = [UIColor blackColor];

Expand All @@ -69,35 +68,35 @@ -(id)initWithReuseIdentifier:(NSString *)aReuseIdentifier andDelegate:(id)aDeleg

self.titleFont = [UIFont systemFontOfSize:18];

imageView = [[UIImageView alloc] initWithFrame:self.bounds];
_imageView = [[UIImageView alloc] initWithFrame:self.bounds];

self.imageView.backgroundColor = [UIColor clearColor];

self.backgroundColor = [UIColor clearColor];

[self addSubview:imageView];
[self addSubview:_imageView];

textLabel = [[UILabel alloc] initWithFrame:self.bounds];
textLabel.textAlignment = UITextAlignmentCenter;
_textLabel = [[UILabel alloc] initWithFrame:self.bounds];
_textLabel.textAlignment = UITextAlignmentCenter;


self.textLabel.backgroundColor = [UIColor clearColor];

imageViewClose = [[UIImageView alloc] initWithFrame:self.bounds];
_imageViewClose = [[UIImageView alloc] initWithFrame:self.bounds];

self.imageViewClose.backgroundColor = [UIColor clearColor];
imageViewClose.image = [UIImage imageNamed:@"tab_close.png"];
imageViewClose.hidden = YES;
_imageViewClose.image = [UIImage imageNamed:@"tab_close.png"];
_imageViewClose.hidden = YES;

self.backgroundColor = [UIColor clearColor];

[self addSubview:imageViewClose];
[self addSubview:textLabel];
[self addSubview:_imageViewClose];
[self addSubview:_textLabel];

[self setSelected:YES];
panGuesture = [[UIPanGestureRecognizer alloc] initWithTarget:delegate
panGuesture = [[UIPanGestureRecognizer alloc] initWithTarget:_delegate
action:@selector(handlePanGuesture:)];
panGuesture.delegate = delegate;
panGuesture.delegate = _delegate;
[self addGestureRecognizer:panGuesture];

}
Expand All @@ -109,18 +108,18 @@ -(void)setSelected:(BOOL)isSelected
_selected = isSelected;

if (isSelected) {
self.textLabel.textColor = selectedTitleColor;
imageView.image = self.tabSelectedImage;
self.textLabel.textColor = _selectedTitleColor;
_imageView.image = self.tabSelectedImage;
if (self.delegate.numberOfTabs>1) {
imageViewClose.hidden = NO;
_imageViewClose.hidden = NO;
}else{
imageViewClose.hidden = YES;
_imageViewClose.hidden = YES;
}

}else{
self.textLabel.textColor = normalTitleColor;
imageView.image = self.tabNormalImage;
imageViewClose.hidden = YES;
self.textLabel.textColor = _normalTitleColor;
_imageView.image = self.tabNormalImage;
_imageViewClose.hidden = YES;
}
}
-(void)prepareForReuse
Expand All @@ -130,24 +129,16 @@ -(void)prepareForReuse
self.delegate = nil;
_selected = NO;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
}
*/

-(void)layoutSubviews
{
title = self.textLabel.text;
CGSize titleSize = [title sizeWithFont:titleFont];
imageView.frame = self.bounds;
_title = self.textLabel.text;
CGSize titleSize = [_title sizeWithFont:_titleFont];
_imageView.frame = self.bounds;

self.textLabel.frame = CGRectMake((self.bounds.size.width - titleSize.width)/2 , (self.bounds.size.height - titleSize.height)/2, titleSize.width,titleSize.height);

imageViewClose.frame = CGRectMake(self.bounds.origin.x+115, self.bounds.origin.y+12, 19, 18);
_imageViewClose.frame = CGRectMake(self.bounds.origin.x+115, self.bounds.origin.y+12, 19, 18);

[super layoutSubviews];
}
Expand All @@ -161,8 +152,6 @@ -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
previousSelected = _selected;
[self setSelected:YES];
[self.delegate setSelectedTabIndex:self.index animated:NO];


}


Expand Down
32 changes: 6 additions & 26 deletions BrowserTabViewDemo/BrowserTabView/BrowserTabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
//

#import <UIKit/UIKit.h>
#import "BrowserTab.h"

@class BrowserTabView;
@class BrowserTab;

@protocol BrowserTabViewDelegate<NSObject>

Expand All @@ -44,35 +43,16 @@
-(void)BrowserTabView:(BrowserTabView *)browserTabView exchangeTabAtIndex:(NSUInteger)fromIndex withTabAtIndex:(NSUInteger)toIndex;
@end

@interface BrowserTabView : UIView<UIGestureRecognizerDelegate>{

// image for the tabview backgroud
UIImage *tabViewBackImage;

NSUInteger numberOfTabs;

NSInteger selectedTabIndex;

//array for saving all the tab
NSMutableArray *tabsArray;

//array for saving frames of tabs
NSMutableArray *tabFramesArray;

// reuse queue holds unused tabs
NSMutableArray *reuseQueue;
id<BrowserTabViewDelegate> delegate;

}
@interface BrowserTabView : UIView<UIGestureRecognizerDelegate>

@property(nonatomic, retain) UIImage *tabViewBackImage;
@property(nonatomic, strong) UIImage *tabViewBackImage;
@property(nonatomic, assign) NSUInteger numberOfTabs;
@property(nonatomic, assign) NSInteger selectedTabIndex;
@property(nonatomic, retain) NSMutableArray *tabsArray;
@property(nonatomic, retain) NSMutableArray *tabFramesArray;
@property(nonatomic, strong) NSMutableArray *tabsArray;
@property(nonatomic, strong) NSMutableArray *tabFramesArray;

@property(nonatomic, readonly) NSMutableArray *reuseQueue;
@property(nonatomic, assign) id<BrowserTabViewDelegate> delegate;
@property(nonatomic, weak) id<BrowserTabViewDelegate> delegate;

-(id)initWithTabTitles:(NSArray *)titles andDelegate:(id)adelegate;
-(void)addTabWithTitle:(NSString *)title;
Expand Down
Loading

0 comments on commit 3789418

Please sign in to comment.