Images in Carousel View einbinden

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Images in Carousel View einbinden

    Hallo Zusammen.

    Ich stocke nun schon seit ein paar Tagen an meinem Code. Ich möchte ein "Carousel View" als Kartendeck darstellen. Hab soweit alles zum laufen gebracht, jedoch hänge ich beim einbinden der Bilder fest. Was hab ich übersehen?? Ich hoffe, ihr könnt mir weiter helfen...

    Danke schon mal für eure Hilfe :) :thumbsup:

    Quellcode

    1. #import "ViewController.h"
    2. const static int kCardsCount = 7;
    3. @interface ViewController ()
    4. @end
    5. @implementation ViewController
    6. - (void)viewDidLoad {
    7. [super viewDidLoad];
    8. UPCardsCarousel *carousel = [[UPCardsCarousel alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20)];
    9. [carousel setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
    10. [carousel.labelBanner setBackgroundColor:[UIColor colorWithRed:0.96 green:0.76 blue:0.74 alpha:1.]];
    11. [carousel setLabelFont:[UIFont boldSystemFontOfSize:17.0f]];
    12. [carousel setLabelTextColor:[UIColor whiteColor]];
    13. [carousel setDelegate:self];
    14. [carousel setDataSource:self];
    15. [self.view addSubview:carousel];
    16. collectionImages = [NSArray arrayWithObjects:@"FPSilber.png",@"FKSilber.png",@"FPRose.png",@"FKRose.png",@"FPGold.png",@"FKGold.png",@"Fleder.png", nil];
    17. }
    18. #pragma mark - CardsCarouselDataSource Methods
    19. - (NSUInteger)numberOfCardsInCarousel:(UPCardsCarousel *)carousel
    20. {
    21. return kCardsCount;
    22. }
    23. - (UIView*)carousel:(UPCardsCarousel *)carousel viewForCardAtIndex:(NSUInteger)index
    24. {
    25. NSString *label = [NSString stringWithFormat:@"%i", (int)index];
    26. return [self createCardViewWithLabel:label];
    27. }
    28. - (NSString*)carousel:(UPCardsCarousel *)carousel labelForCardAtIndex:(NSUInteger)index
    29. {
    30. return [NSString stringWithFormat:@"Card %i", (int)index];
    31. }
    32. #pragma mark - CardsCarouselDelegate Methods
    33. - (void)carousel:(UPCardsCarousel *)carousel didTouchCardAtIndex:(NSUInteger)index
    34. {
    35. NSString *message = [NSString stringWithFormat:@"Card %i touched", (int)index];
    36. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:message
    37. message:nil
    38. delegate:nil
    39. cancelButtonTitle:@"Ok"
    40. otherButtonTitles:nil];
    41. [alert show];
    42. }
    43. #pragma mark - Helpers
    44. - (UIView*)createCardViewWithLabel:(NSString*)label
    45. {
    46. UIView *cardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 240)];
    47. [cardView setBackgroundColor:[UIColor colorWithRed:180./255. green:180./255. blue:180./255. alpha:1.]];
    48. [cardView.layer setShadowColor:[UIColor blackColor].CGColor];
    49. [cardView.layer setShadowOpacity:.5];
    50. [cardView.layer setShadowOffset:CGSizeMake(0, 0)];
    51. [cardView.layer setBorderColor:[UIColor whiteColor].CGColor];
    52. [cardView.layer setBorderWidth:10.];
    53. [cardView.layer setCornerRadius:4.];
    54. UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectInset(cardView.frame, 20, 20)];
    55. [labelView setCenter:CGPointMake(cardView.frame.size.width/2, cardView.frame.size.height/2)];
    56. [labelView setFont:[UIFont boldSystemFontOfSize:100]];
    57. [labelView setTextAlignment:NSTextAlignmentCenter];
    58. [labelView setTextColor:[UIColor grayColor]];
    59. [labelView setText:label];
    60. [cardView addSubview:labelView];
    61. return cardView;
    62. }
    63. @end
    Alles anzeigen
  • Hallo MCDan,

    danke für die Antwort. Denk ich dann richtig, wenn ich die "collectionImages = [NSArray arrayWithObjects:@"FPSilber.png",@"FKSilber.png",@"FPRose.png",@"FKRose.png",@"FPGold.png",@"FKGold.png",@"Fleder.png", nil];" direkt in die *cardview einbaue? Und wie kann ich statt der Numerischen Aufzählung im Label einen bestimmten Text angezeigt? Hab nach längerem suchen zwar ein Beispielcode gefunden, aber leider nur in Swift und ich bekomm den nicht auf Objective-C umgewandelt ?(