Skip to content

Latest commit

 

History

History
196 lines (143 loc) · 4.06 KB

README.md

File metadata and controls

196 lines (143 loc) · 4.06 KB

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
class ViewController: UIViewController, ZSeatSelectorDelegate {
}

**Create your map using a NSString.**

Note:
A = Available
U = Unavailable
D = Disabled
_ = Space
/ = Line Break (row)

Obj-C
NSString *map =     @"AAAAA_DAAAA/"
                    @"UAAAA_DAAAA/"
                    @"UUUUU_DAAAA/"
                    @"UAAAA_AAAAA/"
                    @"AAAAA_AAAAA/";
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
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
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
    [seat setSelected_seat_limit:3];
    
Swift
    seats2.selected_seat_limit = 5
    

Add the delegate functions

Obj-C
- (void)seatSelected:(ZSeat *)seat{
    NSLog(@"Seat at Row:%ld and Column:%ld", (long)seat.row,(long)seat.column);
}
-(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
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")
    }
    

Zooming
Set the zoom as you would with a UIScrollView properties: minimumZoomScale
maximimZoomScale

Hope you find it useful.

Follow me on Twitter @richzertuche