我有两个按钮,每个按钮的左侧都有一个徽章标签,但我希望这些徽章标签的大小是动态的,我现在该怎么做是这样的
当我启动应用程序时
但是当我向上滚动孔单元时,它应该是这样的
使用 iPhone sdk 6.0:
#import <QuartzCore/QuartzCore.h>
#import "JSMBadgeLabel.h"
@interface JSMBadgeLabel ()
-(void) setup;
@end
@implementation JSMBadgeLabel
@synthesize targetUIView = _targetUIView;
-(void) setup{
self.layer.cornerRadius = self.font.pointSize *0.8;
}
-(void)awakeFromNib
{
[self setup];
}
-(void)setText:(NSString *)text{
[super setText:text];
CGSize size = [text sizeWithFont:self.font];
self.frame = CGRectMake(self.frame.origin.x ,self.frame.origin.y,size.width + self.font.pointSize *0.8,size.height);
CGRect badgeFrame = self.frame;
CGRect targetFrame = self.targetUIView.frame;
self.frame = CGRectMake(targetFrame.origin.x+targetFrame.size.width- badgeFrame.size.width/2,targetFrame.origin.y-badgeFrame.size.height/2,badgeFrame.size.width,badgeFrame.size.height);}@end
-(void) updateAsBadge:(NSString*)newText {
self.text = newText;
[self sizeToFit];
const int padding = 1;
self.frame = CGRectMake(self.superview.bounds.size.width - self.bounds.size.width-padding, padding, self.bounds.size.width, self.bounds.size.height);
}
谢谢。