我是iOS新手,並且遇到關於在fount Awesome按鈕上顯示通知計數的問題。 我的代碼是這樣的我如何顯示目標C中的UINavigation欄上的通知計數
// Notificaation圖標按鈕...
UILabel *lablnotification =[[UILabel alloc] init];
// lab.font = [UIFont fontWithName:@"FontAwesome" size:8];
// lab.textColor = [UIColor whiteColor];
lablnotification.text = [NSString awesomeIcon:FaBell];
UIImage *listImage4 = [UIImage imageNamed:@"notification.png"];
UIButton *listButton4 = [UIButton buttonWithType:UIButtonTypeCustom];
listButton4.backgroundColor=[UIColor whiteColor];
[[listButton4 layer] setBorderWidth:0.5f];
listButton4.layer.borderColor =[[UIColor blackColor] CGColor];
listButton4.layer.cornerRadius = managementbtn.bounds.size.width/3.4;// this value vary as per your desire
listButton4.clipsToBounds = YES;
UIFont *fontnotification = [UIFont fontWithName:@"FontAwesome" size:15.0];
UIColor *colornotification = [UIColor blueColor];
NSDictionary *attrsDictionarynotification = [NSDictionary dictionaryWithObjectsAndKeys:fontnotification,NSFontAttributeName,colornotification,NSForegroundColorAttributeName, nil];
// [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,color,NSForegroundColorAttributeName, nil];
NSAttributedString *attributedStrnotification = [[NSAttributedString alloc] initWithString:lablnotification.text attributes:attrsDictionarynotification];
// get the image size and apply it to the button frame
CGRect listButton4Frame = listButton4.frame;
listButton4Frame.size = listImage4.size;
listButton4.frame = listButton4Frame;
[listButton4 setAttributedTitle:attributedStrnotification forState:UIControlStateNormal];
[listButton4 addTarget:self
action:@selector(ActualNotificationClick:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton4 =
[[UIBarButtonItem alloc] initWithCustomView:listButton4];
方法
-(void)ActualNotificationClick:(id)sender
{
if([CheckStringVersion isEqualToString:@"1"])
{
NotificationScreen *screen =[[NotificationScreen alloc] initWithNibName:@"NotificationScreen" bundle:nil];
[self.navigationController pushViewController:screen animated:YES];
}
else
{
[email protected]"3";
UIAlertView *alertPOP =[[UIAlertView alloc] initWithTitle:@"No Update Require" message:@"App is up to date." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertPOP show];
}
}
我需要表現出這樣的
如何通知我可以展示它嗎? 在此先感謝!
@SiddeshMhatra我需要證明它lablnotification。 – Muju
在'UILabel * bagdeLabel = [self DisplayBagde:30:10:'your notification count'];' –
添加徽章數你想要的東西傳遞你的x和y座標(你希望顯示在視圖上)like ur case x = btn.width-10,y = 0和通知計數。 –