Browse files

Converted to ARC. Cleaned up the code.

* added copy to the license to CoolButton .h and .m
* removed NSLog from CoolButton .h and .m
  • Loading branch information...
1 parent d3b53de commit 95e2a9a19ab043a4d652f2d1cc8667422b846991 @bejo bejo committed Oct 7, 2011
View
5 CoolButtons.xcodeproj/project.pbxproj
@@ -290,6 +290,7 @@
7DE6AD4C1357F100007D6B75 /* Project object */ = {
isa = PBXProject;
attributes = {
+ LastUpgradeCheck = 0420;
ORGANIZATIONNAME = "Relevance, Inc.";
};
buildConfigurationList = 7DE6AD4F1357F100007D6B75 /* Build configuration list for PBXProject "CoolButtons" */;
@@ -441,10 +442,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CoolButtons/CoolButtons-Prefix.pch";
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "CoolButtons/CoolButtons-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.2;
LIBRARY_SEARCH_PATHS = (
@@ -460,10 +463,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CoolButtons/CoolButtons-Prefix.pch";
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "CoolButtons/CoolButtons-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.2;
LIBRARY_SEARCH_PATHS = (
View
48 CoolButtons/CoolButton.h 100644 → 100755
@@ -1,24 +1,40 @@
-//
-// CoolButton.h
-// CoolButtons
-//
-// Created by Jess Martin on 4/14/11.
-// Copyright 2011 Relevance, Inc. All rights reserved.
-//
+/*
+ * Author: Jess Martin
+ *
+ * Copyright (c) 2011 Jess Martin.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
#import <Foundation/Foundation.h>
-@interface CoolButton : UIButton {
- UIColor *_buttonColor;
- UIView *_innerView;
- CALayer *_highlightLayer;
-}
+@interface CoolButton : UIButton
-@property (nonatomic, retain)UIColor *buttonColor;
-@property (nonatomic, retain)UIView *innerView;
-@property (nonatomic, retain)CALayer *highlightLayer;
-- (void)setButtonColor:(UIColor *)buttonColor;
+@property (nonatomic, strong) UIColor *buttonColor;
+@property (nonatomic, strong) UIView *innerView;
+@property (nonatomic, strong) CALayer *highlightLayer;
+
@end
View
107 CoolButtons/CoolButton.m 100644 → 100755
@@ -1,84 +1,116 @@
-//
-// CoolButton.m
-// CoolButtons
-//
-// Created by Jess Martin on 4/14/11.
-// Copyright 2011 Relevance, Inc. All rights reserved.
-//
+/*
+ * Author: Jess Martin
+ *
+ * Copyright (c) 2011 Jess Martin.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
#import <QuartzCore/QuartzCore.h>
#import "CoolButton.h"
+
@interface CoolButton (PrivateMethods)
-- (void) buildView;
+- (void)_buildView;
@end
+
@implementation CoolButton
-@synthesize buttonColor=_buttonColor;
-@synthesize innerView=_innerView;
-@synthesize highlightLayer=_highlightLayer;
-- (void) awakeFromNib {
- NSLog(@"Awake from nib called");
+@synthesize buttonColor = _buttonColor;
+@synthesize innerView = _innerView;
+@synthesize highlightLayer = _highlightLayer;
+
+
+- (UIColor *)buttonColor
+{
+ return _buttonColor;
+}
+
+
+- (void)setButtonColor:(UIColor *)buttonColor
+{
+ _buttonColor = buttonColor;
+ [self.innerView setBackgroundColor:[self buttonColor]];
+}
+
+
+- (void)awakeFromNib
+{
[self setButtonColor:[self backgroundColor]];
[self setBackgroundColor:[UIColor clearColor]];
- [self buildView];
+ [self _buildView];
}
+
- (id)initWithFrame:(CGRect)frame
{
- NSLog(@"Init called");
- if ((self=[super initWithFrame:frame]))
+ if ((self = [super initWithFrame:frame]))
{
[self setButtonColor:[UIColor colorWithRed:73/255.0 green:107/255.0 blue:155/255.0 alpha:1.0]];
- [self buildView];
+ [self _buildView];
}
return self;
}
--(void) buildView
+
+- (void)_buildView
{
- self.innerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)] autorelease];
+ self.innerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
[self.innerView setUserInteractionEnabled:false];
[self addTarget:self action:@selector(addHighlight) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(removeHighlight) forControlEvents:UIControlEventTouchCancel|UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
- if ([[self subviews] count] > 0)
+ if ([[self subviews] count] > 0) {
[self insertSubview:self.innerView belowSubview:[[self subviews] objectAtIndex:0]];
- else
+ } else {
[self addSubview:self.innerView];
+ }
self.highlightLayer = [CALayer layer];
[self.highlightLayer setAnchorPoint:CGPointMake(0, 0)];
[self.highlightLayer setBounds:[self bounds]];
[self.highlightLayer setBackgroundColor:[[UIColor colorWithWhite:0.0 alpha:0.3] CGColor]];
}
--(void)addHighlight
+
+- (void)addHighlight
{
- NSLog(@"adding highlight layer");
[[self.innerView layer] insertSublayer:self.highlightLayer atIndex:3];
}
--(void)removeHighlight
+
+- (void)removeHighlight
{
- NSLog(@"removing highlight layer");
[self.highlightLayer removeFromSuperlayer];
}
-- (void)setButtonColor:(UIColor *)value
-{
- [_buttonColor autorelease];
- _buttonColor = [value retain];
- [self.innerView setBackgroundColor:[self buttonColor]];
-}
--(void)drawRect:(CGRect)rect
+- (void)drawRect:(CGRect)rect
{
- NSLog(@"drawing the rect!");
- for (int i = 0; i < [[[self.innerView layer] sublayers] count]; i++ ) {
+ for (int i = 0; i < [[[self.innerView layer] sublayers] count]; i++) {
[[[[self.innerView layer] sublayers] objectAtIndex:0] removeFromSuperlayer];
}
// create a view to store all the content
@@ -123,12 +155,5 @@ -(void)drawRect:(CGRect)rect
[[self layer] setCornerRadius:5.0];
}
--(void)dealloc
-{
- self.innerView = nil;
- self.highlightLayer = nil;
- self.buttonColor = nil;
- [super dealloc];
-}
@end
View
4 CoolButtons/CoolButtonsAppDelegate.h
@@ -13,7 +13,7 @@
CoolButtonsViewController *viewController;
}
-@property (nonatomic, retain) IBOutlet UIWindow *window;
-@property (nonatomic, retain) CoolButtonsViewController *viewController;
+@property (nonatomic, strong) IBOutlet UIWindow *window;
+@property (nonatomic, strong) CoolButtonsViewController *viewController;
@end
View
6 CoolButtons/CoolButtonsAppDelegate.m
@@ -79,11 +79,5 @@ - (void)applicationWillTerminate:(UIApplication *)application
*/
}
-- (void)dealloc
-{
- [_viewController release];
- [_window release];
- [super dealloc];
-}
@end
View
14 CoolButtons/CoolButtonsViewController.h
@@ -27,12 +27,12 @@
- (IBAction)didTouchCancelJessMartDotIn:(id)sender;
- (IBAction)showColorPicker:(id)sender;
-@property(retain, nonatomic) IBOutlet UISlider *redSlider;
-@property(retain, nonatomic) IBOutlet UISlider *greenSlider;
-@property(retain, nonatomic) IBOutlet UISlider *blueSlider;
-@property(retain, nonatomic) IBOutlet UIButton *myPic;
-@property(retain, nonatomic) IBOutlet UIImageView *aintSheABeaut;
-@property(retain, nonatomic) IBOutlet UIView *colorPickerView;
-@property(retain, nonatomic) CoolButton *blueButton;
+@property(strong, nonatomic) IBOutlet UISlider *redSlider;
+@property(strong, nonatomic) IBOutlet UISlider *greenSlider;
+@property(strong, nonatomic) IBOutlet UISlider *blueSlider;
+@property(strong, nonatomic) IBOutlet UIButton *myPic;
+@property(strong, nonatomic) IBOutlet UIImageView *aintSheABeaut;
+@property(strong, nonatomic) IBOutlet UIView *colorPickerView;
+@property(strong, nonatomic) CoolButton *blueButton;
@end
View
5 CoolButtons/CoolButtonsViewController.m
@@ -19,11 +19,6 @@ @implementation CoolButtonsViewController
@synthesize aintSheABeaut;
@synthesize colorPickerView;
-- (void)dealloc
-{
- [self.view release];
- [super dealloc];
-}
- (void)didReceiveMemoryWarning
{
View
8 CoolButtons/main.m
@@ -10,8 +10,8 @@
int main(int argc, char *argv[])
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- int retVal = UIApplicationMain(argc, argv, nil, nil);
- [pool release];
- return retVal;
+ @autoreleasepool {
+ int retVal = UIApplicationMain(argc, argv, nil, nil);
+ return retVal;
+ }
}

0 comments on commit 95e2a9a

Please sign in to comment.