iOS座位选择布局:ZSeatSelector
jopen
9年前
ZSeatSelector 是一个用 Objective-C 写的座位选择布局。
You need to import ZSeatSelector and ZSeat. Also add the ZSeatSelector Delegate to your Controller: #import "ZSeatSelector.h" #import "ZSeat.h" @interface ViewController : UIViewController <ZSeatSelectorDelegate>{ }
Create your map using a NSString.
Note:
A = Available
U = Unavailable
D = Disabled
_ = Space
/ = Line Break (row)
NSString *map = @"AAAAA_DAAAA/" @"UAAAA_DAAAA/" @"UUUUU_DAAAA/" @"UAAAA_AAAAA/" @"AAAAA_AAAAA/";
** Create a ZSeatSelector Object as a UIScrollView **
Set Seat Size
Set Images
Set Seat Price
Finally Set Map
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];
*Add the delegate functions *
- (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); }