Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
UI7Switch Size & Position tuning / MBSwitch option
Browse files Browse the repository at this point in the history
issue #15 #59
  • Loading branch information
youknowone committed Aug 4, 2013
1 parent 730ffc7 commit ca26a13
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions UI7Kit/UI7Switch.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@
//

#import "UI7Switch.h"
#import <KLSwitch/KLSwitch.h>

#if !defined(UI7SWITCH_KLSWITCH) && !defined(UI7SWITCH_MBSWITCH)
# define UI7SWITCH_KLSWITCH 1
#endif

#if UI7SWITCH_KLSWITCH
# import <KLSwitch/KLSwitch.h>
# define UI7SwitchImplementation KLSwitch
#elif UI7SWITCH_MBSWITCH
# import <MBSwitch/MBSwitch.h>
@interface MBSwitch (Private)
- (void)configure;
@end
# define UI7SwitchImplementation MBSwitch
#else
# error UI7Switch implementation class is missing.
#endif

@implementation UISwitch (Patch)

- (id)__initWithCoder:(NSCoder *)aDecoder { assert(NO); return nil; }
- (id)__initWithFrame:(CGRect)frame { assert(NO); return nil; }
- (void)__awakeFromNib { assert(NO); }

@end

Expand All @@ -25,6 +42,9 @@ + (void)initialize {

[target copyToSelector:@selector(__initWithCoder:) fromSelector:@selector(initWithCoder:)];
[target copyToSelector:@selector(__initWithFrame:) fromSelector:@selector(initWithFrame:)];
#if UI7SWITCH_MBSWITCH
[self exportSelector:@selector(awakeFromNib) toClass:[UI7SwitchImplementation class]];
#endif
}
}

Expand All @@ -39,8 +59,11 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
[self release];

//Reassign self and set to a KLSwitch copying propertie from dummy
self = (UI7Switch *)[[KLSwitch alloc] initWithCoder:aDecoder];
self = (UI7Switch *)[[UI7SwitchImplementation alloc] initWithCoder:aDecoder];
if (self != nil) {
#if UI7SWITCH_MBSWITCH
[self configure];
#endif
BOOL on = [aDecoder decodeBoolForKey:@"UISwitchOn"];
[self setOn:on animated:NO];
if ([aDecoder containsValueForKey:@"UISwitchOnTintColor"]) {
Expand All @@ -51,14 +74,31 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
if ([aDecoder containsValueForKey:@"UISwitchThumbTintColor"]) {
self.thumbTintColor = [aDecoder decodeObjectForKey:@"UISwitchThumbTintColor"];
}
CGRect frame = self.frame;
if (frame.size.width != 51.0f) {
frame.size.height = 31.0f;
#if UI7SWITCH_KLSWITCH
frame.origin.x += 20.0f;
#elif UI7SWITCH_MBSWITCH
frame.origin.x += (frame.size.width - 51.0f) / 2;
#endif
frame.size.width = 51.0f;
self.frame = frame;
}
}
return self;
}

#if UI7SWITCH_MBSWITCH
- (void)awakeFromNib {

}
#endif

- (id)initWithFrame:(CGRect)frame {
[self release];
//Reassign self and set to a KLSwitch copying propertie from dummy
self = (UI7Switch *)[[KLSwitch alloc] initWithFrame:frame];
self = (UI7Switch *)[[UI7SwitchImplementation alloc] initWithFrame:frame];
return self;
}
@end

0 comments on commit ca26a13

Please sign in to comment.