ios自定义BadgeValue


//
// 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值