Coder Social home page Coder Social logo

zseatselector's Introduction

ZSeatSelector

Objective-C & Swift / Create a Seat Map Layout

alt tag

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

Obj-C
#import "ZSeatSelector.h"
#import "ZSeat.h"

@interface ViewController : UIViewController <ZSeatSelectorDelegate>{
}
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];
<h6>Swift</h6>
```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") } ```
func getSelectedSeats(seats: NSMutableArray) {
        var total:Float = 0.0;
        for i in 0..<seats.count {
            let seat:ZSeat  = seats.objectAtIndex(i) as! ZSeat
            print("Seat at row: \(seat.row) and column: \(seat.column)\n")
            total += seat.price
        }
        print("----- Total -----\n")
        print("----- \(total) -----\n")
    }

Hope you find it useful.

Follow me on Twitter @richzertuche

zseatselector's People

Contributors

richzertuche avatar

Watchers

Chew Chit Siang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.