Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/richzertuche/ZSeatSelector

Create a Seat Map Layout
https://github.com/richzertuche/ZSeatSelector

cinema objective-c plane seats swift uiscrollview

Last synced: 3 months ago
JSON representation

Create a Seat Map Layout

Awesome Lists containing this project

README

        

# ZSeatSelector

Objective-C & Swift / Create a Seat Map Layout

![alt tag](http://i59.tinypic.com/2enawbc.png)

**You need to import ZSeatSelector and ZSeat. Also add the ZSeatSelector Delegate to your Controller:**

Obj-C

```obj-c

#import "ZSeatSelector.h"
#import "ZSeat.h"

@interface ViewController : UIViewController {
}

```

Swift

```swift

class ViewController: UIViewController, ZSeatSelectorDelegate {
}

```



**Create your map using a NSString.**

Note:


A = Available


U = Unavailable


D = Disabled


_ = Space


/ = Line Break (row)

Obj-C

```obj-c

NSString *map = @"AAAAA_DAAAA/"
@"UAAAA_DAAAA/"
@"UUUUU_DAAAA/"
@"UAAAA_AAAAA/"
@"AAAAA_AAAAA/";
```

Swift

```Swift

let map2:String = "_DDDDDD_DDDDDD_DDDDDDDD_/" +
"_AAAAAA_AAAAAA_DUUUAAAA_/" +
"________________________/" +
"_AAAAAUUAAAUAAAAUAAAAAAA/" +
"_UAAUUUUUUUUUUUUUUUAAAAA/" +
"_AAAAAAAAAAAUUUUUUUAAAAA/" +
"_AAAAAAAAUAAAAUUUUAAAAAA/" +
"_AAAAAUUUAUAUAUAUUUAAAAA/"
```



**Create a ZSeatSelector Object as a UIScrollView**

Set Seat Size


Set Images


Set Seat Price


Finally Set Map

Obj-C

```obj-c

ZSeatSelector *seat = [[ZSeatSelector alloc]initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, 160)];

[seat setSeatSize:CGSizeMake(32, 32)];
[seat setAvailableImage:[UIImage imageNamed:@"A"]
andUnavailableImage:[UIImage imageNamed:@"U"]
andDisabledImage:[UIImage imageNamed:@"D"]
andSelectedImage:[UIImage imageNamed:@"S"]];
[seat setSeat_price:30];
[seat setMap:map];
[seat setDelegate:self];
```

Swift

```swift
let seats2 = ZSeatSelector()
seats2.frame = CGRectMake(0, 250, self.view.frame.size.width, 200)
seats2.setSeatSize(CGSize(width: 30, height: 30))
seats2.setAvailableImage( UIImage(named: "A")!,
andUnavailableImage: UIImage(named: "U")!,
andDisabledImage: UIImage(named: "D")!,
andSelectedImage: UIImage(named: "S")!)
seats2.setMap(map2)
seats2.seat_price = 5.0
seats2.selected_seat_limit = 5
seats2.seatSelectorDelegate = self
self.view.addSubview(seats2)
```



**Seat Limit**


You can now add Seat Limit so that if you only allow to select 3 seats, the last 3 seats the user select are the ones that will be shown, deselecting the previous ones

Obj-C

```obj-c

[seat setSelected_seat_limit:3];

```

Swift

```swift

seats2.selected_seat_limit = 5

```

**Add the delegate functions**

Obj-C

```obj-c

- (void)seatSelected:(ZSeat *)seat{
NSLog(@"Seat at Row:%ld and Column:%ld", (long)seat.row,(long)seat.column);
}

```

```obj-c

-(void)getSelectedSeats:(NSMutableArray *)seats{
float total=0;
for (int i=0; i<[seats count]; i++) {
ZSeat *seat = [seats objectAtIndex:i];
printf("Seat[%ld,%ld]\n",(long)seat.row,(long)seat.column);
total += seat.price;
}
printf("--------- Total: %f\n",total);
}

```

Swift

```swift

func seatSelected(seat: ZSeat) {
print("Seat at row: \(seat.row) and column: \(seat.column)\n")
}

```

```swift

func getSelectedSeats(seats: NSMutableArray) {
var total:Float = 0.0;
for i in 0..
Set the zoom as you would with a UIScrollView properties:
minimumZoomScale

maximimZoomScale

Hope you find it useful.


Follow me on Twitter @richzertuche