Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation SponsorBannerView{
- }
- @synthesize bannerImage;
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- }
- return self;
- }
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect{
- //get the sponsors banners and id's.
- DataBase * dataBase = [[DataBase alloc] init];
- [dataBase openDB];
- NSMutableDictionary *BannersAndId = [dataBase getBanners];
- NSLog(@"banner and id's : %@",BannersAndId);
- //create an id array and a banner array.
- self.poiIDs = [BannersAndId allKeys];
- self.banners = [BannersAndId allValues];
- //get the root file path for the images
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- //create an array to hold the image
- NSMutableArray * images = [[NSMutableArray alloc]init];
- //create an array containing all the images
- for (int i = 0; i<self.banners.count; i++) {
- NSString *tmp = [NSString stringWithFormat:@"%@/%@",documentsDirectory, self.banners[i]];
- UIImage * tmpIamge = [UIImage imageWithContentsOfFile:tmp];
- [images addObject:tmpIamge];
- }
- //cast the mutable array into an array
- NSArray *array = [NSArray arrayWithArray:images];
- //set all the banner settings
- bannerImage=[[UIImageView alloc]init];
- bannerImage.frame=CGRectMake(0, 0, 320, 50);
- bannerImage.backgroundColor=[UIColor purpleColor];
- [bannerImage setAnimationImages:array];
- [bannerImage setAnimationDuration:6];
- [bannerImage setAnimationRepeatCount:0];
- [bannerImage startAnimating];
- //add to view.
- [self addSubview:bannerImage];
- // add a uibutton on top of the uiimageview and assign an action for it
- UIButton* actionButton=[UIButton buttonWithType:UIButtonTypeCustom];
- actionButton.frame=CGRectMake(0, 0, 320, 50);
- [actionButton addTarget:self action:@selector(sponsorBannerAction) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:actionButton];
- }
- -(void) sponsorBannerAction{
- // do what ever here like going to an other uiviewController as you mentionned
- NSLog(@"Pressed");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement