Question

I am newbie for iPhone development.i just create application like chat application.simple i use JSON parsing method and i call the data from server through PHP and send back to them. so i have one UIButton i would like to set badge on this UIButton i already set the badge through some coding like:

on time of viewdid load: *.m file*

self.badgeFive = [[MKNumberBadgeView alloc] initWithFrame:CGRectMake(self.next7.frame.size.width - 22,-20,44,40)];
[self.next7 addSubview:self.badgeFive];

in .h file:

@property (retain) MKNumberBadgeView* badgeFive;
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *next7;

in this above code next7 is click event.i can successfully add the badge on this button but faild to move to the next page.i cant click this button now. on next7 event i call this page:

-(IBAction)next7{
    msgfromuserViewController *tenth = [[msgfromuserViewController alloc] initWithNibName:nil bundle:nil];
   [self presentViewController:tenth animated:YES completion:NULL];
}

so i need to show badges and as well as click this button and want to move to the next page. and simultaneously badge will show the number that are unread message.

Is there any sample code or source code for this type of application which can manage the click event as well as shows the badges for unread message. i wonder a lot but i cant understand how can i develop?

Was it helpful?

Solution

enter image description here

    UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
            [button setBackgroundImage:[UIImage imageNamed:@"cart_icon.png"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(Cart_btn:) forControlEvents:UIControlEventTouchUpInside];
            [button.imageView setContentMode:UIViewContentModeScaleToFill];
            [button setFrame:CGRectMake(0, 0, 36, 33)];
            [self.view addSubview:button];



  UILabel *lbl_card_count = [[UILabel alloc]initWithFrame:CGRectMake(23,0, 13, 13)];
                lbl_card_count.textColor = [UIColor whiteColor];
                lbl_card_count.textAlignment = NSTextAlignmentCenter;
                lbl_card_count.text = [NSString stringWithFormat:@"%d",Temp_card_count];
                lbl_card_count.layer.borderWidth = 1;
                lbl_card_count.layer.cornerRadius = 8;
                lbl_card_count.layer.masksToBounds = YES;
                lbl_card_count.layer.borderColor =[[UIColor clearColor] CGColor];
                lbl_card_count.layer.shadowColor = [[UIColor clearColor] CGColor];
                lbl_card_count.layer.shadowOffset = CGSizeMake(0.0, 0.0);
                lbl_card_count.layer.shadowOpacity = 0.0;
                lbl_card_count.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:45.0/255.0 blue:143.0/255.0 alpha:1.0];
                lbl_card_count.font = [UIFont fontWithName:@"ArialMT" size:11];
                [self.view addSubview:lbl_card_count];
                [lbl_card_count release];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top