Advertisement
wkerswell

Ad banner

Jan 8th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @implementation SponsorBannerView{
  2.  
  3. }
  4.  
  5.  
  6. @synthesize bannerImage;
  7.  
  8. - (id)initWithFrame:(CGRect)frame
  9. {
  10.     self = [super initWithFrame:frame];
  11.     if (self) {
  12.         // Initialization code
  13.     }
  14.     return self;
  15. }
  16.  
  17.  
  18. // Only override drawRect: if you perform custom drawing.
  19. // An empty implementation adversely affects performance during animation.
  20. - (void)drawRect:(CGRect)rect{
  21.    
  22.     //get the sponsors banners and id's.
  23.     DataBase * dataBase = [[DataBase alloc] init];
  24.     [dataBase openDB];
  25.     NSMutableDictionary *BannersAndId = [dataBase getBanners];
  26.     NSLog(@"banner and id's : %@",BannersAndId);
  27.    
  28.     //create an id array and a banner array.
  29.     self.poiIDs = [BannersAndId allKeys];
  30.     self.banners = [BannersAndId allValues];
  31.    
  32.     //get the root file path for the images
  33.     NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  34.     NSString  *documentsDirectory = [paths objectAtIndex:0];
  35.  
  36.     //create an array to hold the image
  37.     NSMutableArray * images = [[NSMutableArray alloc]init];
  38.    
  39.     //create an array containing all the images
  40.     for (int i = 0; i<self.banners.count; i++) {
  41.         NSString *tmp = [NSString stringWithFormat:@"%@/%@",documentsDirectory, self.banners[i]];
  42.         UIImage * tmpIamge = [UIImage imageWithContentsOfFile:tmp];
  43.         [images addObject:tmpIamge];
  44.     }
  45.    
  46.  
  47.     //cast the mutable array into an array
  48.     NSArray *array = [NSArray arrayWithArray:images];
  49.  
  50.     //set all the banner settings
  51.     bannerImage=[[UIImageView alloc]init];
  52.     bannerImage.frame=CGRectMake(0, 0, 320, 50);
  53.     bannerImage.backgroundColor=[UIColor purpleColor];
  54.     [bannerImage setAnimationImages:array];
  55.     [bannerImage setAnimationDuration:6];
  56.     [bannerImage setAnimationRepeatCount:0];
  57.     [bannerImage startAnimating];
  58.    
  59.    
  60.     //add to view.
  61.     [self addSubview:bannerImage];
  62.    
  63.     // add a uibutton on top of the uiimageview and assign an action for it
  64.     UIButton* actionButton=[UIButton buttonWithType:UIButtonTypeCustom];
  65.     actionButton.frame=CGRectMake(0, 0, 320, 50);
  66.     [actionButton addTarget:self action:@selector(sponsorBannerAction) forControlEvents:UIControlEventTouchUpInside];
  67.    
  68.     [self addSubview:actionButton];
  69. }
  70.  
  71. -(void) sponsorBannerAction{
  72.     // do what ever here like going to an other uiviewController as you mentionned
  73.     NSLog(@"Pressed");
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement