//
// ViewController.m
// Badge
//
// Created by Bo Xiu on 12-10-23.
// Copyright (c) 2012年 Bo Xiu. All rights reserved.
//
#import "ViewController.h"
#import "JSBadgeView.h"
#import <QuartzCore/QuartzCore.h>
#define kViewBackgroundColor [UIColor colorWithRed:0.357 green:0.757 blue:0.357 alpha:1]
#define kSquareSideLength 64.0f
#define kSquareCornerRadius 10.0f
#define kMarginBetweenSquares 10.0f
#define kSquareColor [UIColor colorWithRed:0.004 green:0.349 blue:0.616 alpha:1]
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)viewDidAppear:(BOOL)animated{
[self showBadgeValue:@"10"];
}
- (void)showBadgeValue:(NSString *)strBadgeValue
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:scrollView];
UIView *rectangle = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)];
rectangle.backgroundColor = kSquareColor;
rectangle.layer.cornerRadius = kSquareCornerRadius;
rectangle.layer.shadowColor = [UIColor blackColor].CGColor;
rectangle.layer.shadowOffset = CGSizeMake(0.0f, 3.0f);
rectangle.layer.shadowOpacity = 0.4;
rectangle.layer.shadowRadius = 1.0;
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 300,100, 100)];
[imageView setImage:[UIImage imageNamed:@"background.png"][JSBadgeView alloc] initWithParentView:rectangle alignment:JSBadgeViewAlignmentTopRight];
badgeView.badgeText = [NSString stringWithFormat:@"%d",10];
JSBadgeView *badgeView1 = [[JSBadgeView alloc] initWithParentView:imageView alignment:JSBadgeViewAlignmentCenterLeft];
badgeView1.badgeText = [NSString stringWithFormat:@"%d",10];
[scrollView addSubview:imageView];
[scrollView addSubview:rectangle];
[scrollView sendSubviewToBack:rectangle];
}
- (void)removeBadgeValue
{
for (UIView *subview in self.view.subviews) {
NSString *strClassName = [NSString stringWithUTF8String:object_getClassName(subview)];
if ([strClassName isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName isEqualToString:@"_UIBadgeView"]) {
[subview removeFromSuperview];
break;
}
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
JSBadgeView *badgeView = [[JSBadgeView alloc] initWithParentView:rectangle alignment:JSBadgeViewAlignmentTopRight];
badgeView.badgeText = [NSString stringWithFormat:@"%d",10];
JSBadgeView *badgeView1 = [[JSBadgeView alloc] initWithParentView:imageView alignment:JSBadgeViewAlignmentCenterLeft];
badgeView1.badgeText = [NSString stringWithFormat:@"%d",10];
[scrollView addSubview:imageView];
[scrollView addSubview:rectangle];
[scrollView sendSubviewToBack:rectangle];
}
- (void)removeBadgeValue
{
for (UIView *subview in self.view.subviews) {
NSString *strClassName = [NSString stringWithUTF8String:object_getClassName(subview)];
if ([strClassName isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName isEqualToString:@"_UIBadgeView"]) {
[subview removeFromSuperview];
break;
}
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
ios自定义BadgeValue
最新推荐文章于 2021-01-30 10:36:09 发布