ios - 如何在uibutton之类的消息应用程序上使用角标(Badge)?

标签 ios iphone objective-c ios6 objective-c-blocks

我是 iPhone开发的新手。我只是创建像聊天应用程序之类的应用程序。很简单,我使用JSON解析方法,并通过PHP从服务器调用数据并将其发送回给他们。
所以我有一个UIButton我想在此上设置徽章UIButton 我已经通过一些编码设置了徽章:

加载的时间:*。m 文件*

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

.h 文件中:
@property (retain) MKNumberBadgeView* badgeFive;
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *next7;

在上面的代码中,next7是click事件。我可以在此按钮上成功添加徽章,但是无法移动到下一页。我现在不能单击此按钮
next7 事件上,我将此页面称为:
-(IBAction)next7{
    msgfromuserViewController *tenth = [[msgfromuserViewController alloc] initWithNibName:nil bundle:nil];
   [self presentViewController:tenth animated:YES completion:NULL];
}

因此,我需要显示徽章并单击此按钮,然后移至下一页。
同时徽章将显示未读邮件的号码。

对于这种类型的应用程序,是否有任何示例代码或源代码可以管理click事件并显示未读消息的标志。
我很想知道,但我不明白我该如何发展?

最佳答案

    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];

关于ios - 如何在uibutton之类的消息应用程序上使用角标(Badge)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22877446/

相关文章:

iphone - iOS SDK 禁用内置麦克风

ios - performFetchWithCompletionHandler 是否必须在主线程或后台线程中进行 http 提取?

iOS 图表删除条形图条形图上的值

iphone - iPhone 中的 GridView 问题

iphone - 供应商需要的 SKU 编号

iphone - 如何为使用 CGBitmapContextCreate() 创建的绘图 Canvas 设置背景颜色?

c# - 如何在 ios xamarin studio 中生成 xml 文档文件?

objective-c - 以编程方式关闭单个监视器

ios - 在 ScrollView 中显示图像

ios - 在 AVAssetReader 中获取 Exc_Bad_access