Skip to content

Commit

Permalink
Update readme with more information. Show how to toggle switches prog…
Browse files Browse the repository at this point in the history
…ramatically in example.
  • Loading branch information
bvogelzang committed Jun 17, 2013
1 parent 68f295c commit 2398557
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## SevenSwitch

iOS 7 style drop in replacement for UISwitch
iOS7 style drop in replacement for UISwitch

![Animation](https://raw.github.com/bvogelzang/SevenSwitch/master/Examples/example.gif)
![Default](https://raw.github.com/bvogelzang/SevenSwitch/master/Examples/example.png)
Expand All @@ -9,6 +9,8 @@ iOS 7 style drop in replacement for UISwitch

## Usage

To use it, add SevenSwitch.h and SevenSwitch.m files to your project and add the QuartzCore framework to your project.

Initializing and adding the switch to the screen

```objective-c
Expand All @@ -22,6 +24,13 @@ When the user manipulates the switch control ("flips" it) a `UIControlEventValue
[mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
```

You can set images for the on/off states

```objective-c
mySwitch.offImage = [UIImage imageNamed:@"cross.png"];
mySwitch.onImage = [UIImage imageNamed:@"check.png"];
```
You can also customize the switches colors
```objective-c
Expand All @@ -33,10 +42,20 @@ mySwitch.borderColor = [UIColor clearColor];
mySwitch.shadowColor = [UIColor blackColor];
```

You can resize the switch frame to whatever you like to make fatter/skinnier controls

```objective-c
mySwitch.frame = CGRectMake(0, 0, 100, 50);
```

## Requirements

SevenSwitch requires iOS 5.0 and above.

#### ARC

SevenSwitch uses ARC as of its 1.0 release.

## License

Made available under the MIT License. Attribution would be nice.
7 changes: 7 additions & 0 deletions SevenSwitchExample/SevenSwitchExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ - (void)viewDidLoad
[mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch];

// turn the switch on
mySwitch.on = YES;

// Example of a bigger switch with images
SevenSwitch *mySwitch2 = [[SevenSwitch alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
mySwitch2.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 - 80);
Expand All @@ -35,11 +38,15 @@ - (void)viewDidLoad
mySwitch2.onColor = [UIColor colorWithHue:0.08f saturation:0.74f brightness:1.00f alpha:1.00f];
[self.view addSubview:mySwitch2];

// turn the switch on with animation
[mySwitch2 setOn:YES animated:YES];

// Example of color customization
SevenSwitch *mySwitch3 = [[SevenSwitch alloc] initWithFrame:CGRectZero];
mySwitch3.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 + 70);
[mySwitch3 addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch3];

//self.view.backgroundColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f];
mySwitch3.knobColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f];
mySwitch3.activeColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f];
Expand Down

0 comments on commit 2398557

Please sign in to comment.