澎湃iPad上线版本

commentOkButton.m 6.2KB

    // // commentOkButton.m // ThePaperDemo // // Created by scar1900 on 14-9-27. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "commentOkButton.h" @interface commentOkButton() //@property(nonatomic, strong)UIImageView *btnSnapView; @property(nonatomic, strong)UILabel *textLabel; @end @implementation commentOkButton @synthesize text = _text; -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { //5289: 个人动态页,点赞时白底在右侧会凸起一部分(bug:5289) self.backgroundColor = [UIColor clearColor]; [self setTitleColor:[UIColor colorWithHexString:LIGHTGRAY] forState:UIControlStateNormal]; [self setImage:Image(@"detailPage/commentOk.png") forState:UIControlStateNormal]; [self setImage:Image(@"detailPage/commentOk_s.png") forState:UIControlStateSelected]; [self setImage:Image(@"detailPage/commentOk_s.png") forState:UIControlStateHighlighted]; [self addSubview:self.textLabel]; [self setImageEdgeInsets:UIEdgeInsetsMake(0, 5, 15, 5)]; [self subLayoutSubViews]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [self setTitleColor:[UIColor colorWithHexString:LIGHTGRAY] forState:UIControlStateNormal]; _textLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)setNormalImageStr:(NSString *)normalImageStr { [self setImage:Image(normalImageStr) forState:UIControlStateNormal]; } - (UILabel*)textLabel { if (!_textLabel) { _textLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _textLabel.textAlignment = NSTextAlignmentCenter; _textLabel.userInteractionEnabled = YES; _textLabel.backgroundColor = [UIColor clearColor]; _textLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; } _textLabel.font = appFont(8, NO); return _textLabel; } - (void)setText:(NSString *)str { _text = str; self.textLabel.text = str; } //- (UIImageView*)btnSnapView { // if (!_btnSnapView) { // _btnSnapView = [[UIImageView alloc]initWithFrame:CGRectZero]; // UIImage *snapShot = getSnapshotImgFromView(self); // _btnSnapView.image = snapShot; // _btnSnapView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; // } // return _btnSnapView; //} - (void)setSelected:(BOOL)selected { [super setSelected:selected]; if (selected) { self.textLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; self.userInteractionEnabled = NO; }else { self.textLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; self.userInteractionEnabled = YES; } } - (void)setHighlighted:(BOOL)highlighted { // if (self.selected) { // return; // } [super setHighlighted:highlighted]; // if (highlighted) { // self.btnSnapView.frame = self.bounds; // [self addSubview:self.btnSnapView]; // [UIView animateWithDuration:0.2 animations:^{ // self.btnSnapView.transform = CGAffineTransformMakeScale(1.2, 1.2); // }]; // }else { // [UIView animateWithDuration:0.2 animations:^{ // self.btnSnapView.transform = CGAffineTransformMakeScale(1.0, 1.0); // }]; // [self.btnSnapView removeFromSuperview]; // } } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { if (self.selected) { return; } [self setSelected:YES]; if (animated) { CGRect nowRect = [self convertRect:self.bounds toView:KEY_WINDOW]; CGFloat x = nowRect.origin.x; CGFloat y = nowRect.origin.y; CGFloat w = nowRect.size.width; CGFloat h = nowRect.size.height; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x+w/2-6, y+h/4 - 20, 100, 20)]; label.text = @"+1"; label.textColor = [UIColor colorWithHexString:BLUECOLOR]; label.font = appFont(16, NO); label.backgroundColor = [UIColor clearColor]; [UIView animateWithDuration:0.2 animations:^{ self.transform = CGAffineTransformScale(self.transform, 1.1, 1.1); } completion:^(BOOL finished) { [UIView animateWithDuration:0.2 animations:^{ self.transform = CGAffineTransformScale(self.transform, 1.0/1.1, 1.0/1.1); } completion:^(BOOL finished) { [KEY_WINDOW addSubview:label]; CGRect rect = label.frame; rect.origin.y -= 30; [UIView animateWithDuration:0.5 animations:^{ label.frame = rect; label.alpha = 0; } completion:^(BOOL finished) { [label removeFromSuperview]; }]; }]; }]; } } - (void)subLayoutSubViews { self.textLabel.frame = CGRectMake(0, 20, 30, 15); } - (void)changeLabelFrame { self.textLabel.frame = CGRectMake(0, 2.5, 20, 15); } -(void)changeButtonImage{ // self.backgroundColor = [UIColor greenColor]; // self.textLabel.backgroundColor = [UIColor clearColor]; [self setImageEdgeInsets:UIEdgeInsetsMake(0, 10, 15, 0)]; [self setImage:Image(@"other/messagePraise.png") forState:UIControlStateNormal]; [self setImage:Image(@"other/messagePraise_s.png") forState:UIControlStateSelected]; [self setImage:Image(@"other/messagePraise_s.png") forState:UIControlStateHighlighted]; self.textLabel.frame = CGRectMake(0, 7, 20, 15); } -(void)changeButtonImage:(NSString *)norImg selectImg:(NSString *)selImg{ [self setImageEdgeInsets:UIEdgeInsetsMake(0, 10, 15, 0)]; [self setImage:Image(norImg) forState:UIControlStateNormal]; [self setImage:Image(selImg) forState:UIControlStateSelected]; [self setImage:Image(selImg) forState:UIControlStateHighlighted]; self.textLabel.frame = CGRectMake(CGRectGetMinX(self.bounds), CGRectGetMaxY(self.bounds)+5, 20, 15); } @end