@@ -33,26 +33,28 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
3333 _proDesL.textColor = [UIColor colorWithHexString: @" 0x222222" ];
3434 [self .contentView addSubview: _proDesL];
3535 }
36- NSInteger gitBtnNum = 3 ;
37- CGFloat whiteSpace = 7.0 ;
38- CGFloat btnWidth = (kProjectDescriptionCell_ContentWidth - whiteSpace *2 ) /3 ;
39- _gitButtons = [[NSMutableArray alloc ] initWithCapacity: gitBtnNum];
40-
41- for (int i = 0 ; i < gitBtnNum; i++) {
42- EaseGitButton *gitBtn = [EaseGitButton gitButtonWithFrame: CGRectMake (kPaddingLeftWidth + i *(btnWidth +whiteSpace),0 , btnWidth, kScaleFrom_iPhone5_Desgin (33 )) type: i];
43-
44- [gitBtn bk_addEventHandler: ^(EaseGitButton *sender) {
45- if (sender.type == EaseGitButtonTypeStar
46- || sender.type == EaseGitButtonTypeWatch) {
47- gitBtn.checked = !gitBtn.checked ;
48- gitBtn.userNum += gitBtn.checked ? 1 : -1 ;
49- }
50- if (self.gitButtonClickedBlock ) {
51- self.gitButtonClickedBlock (i);
52- }
53- } forControlEvents: UIControlEventTouchUpInside];
54- [self .contentView addSubview: gitBtn];
55- [_gitButtons addObject: gitBtn];
36+ if (!_gitButtons) {
37+ NSInteger gitBtnNum = 3 ;
38+ CGFloat whiteSpace = 7.0 ;
39+ CGFloat btnWidth = (kProjectDescriptionCell_ContentWidth - whiteSpace *2 ) /3 ;
40+ _gitButtons = [[NSMutableArray alloc ] initWithCapacity: gitBtnNum];
41+
42+ for (int i = 0 ; i < gitBtnNum; i++) {
43+ EaseGitButton *gitBtn = [EaseGitButton gitButtonWithFrame: CGRectMake (kPaddingLeftWidth + i *(btnWidth +whiteSpace),0 , btnWidth, kScaleFrom_iPhone5_Desgin (30 )) type: i];
44+
45+ [gitBtn bk_addEventHandler: ^(EaseGitButton *sender) {
46+ if (sender.type == EaseGitButtonTypeStar
47+ || sender.type == EaseGitButtonTypeWatch) {
48+ gitBtn.checked = !gitBtn.checked ;
49+ gitBtn.userNum += gitBtn.checked ? 1 : -1 ;
50+ }
51+ if (self.gitButtonClickedBlock ) {
52+ self.gitButtonClickedBlock (i);
53+ }
54+ } forControlEvents: UIControlEventTouchUpInside];
55+ [self .contentView addSubview: gitBtn];
56+ [_gitButtons addObject: gitBtn];
57+ }
5658 }
5759 }
5860 return self;
@@ -93,8 +95,13 @@ - (void)layoutSubviews{
9395 [super layoutSubviews ];
9496 CGFloat desHeight = [_curProject.description_mine getSizeWithFont: kProjectDescriptionCell_Font constrainedToSize: CGSizeMake (kProjectDescriptionCell_ContentWidth , CGFLOAT_MAX)].height ;
9597 [_proDesL setFrame: CGRectMake (kPaddingLeftWidth , kPaddingLeftWidth , kProjectDescriptionCell_ContentWidth , desHeight)];
98+
99+ CGFloat gitBtnY = kPaddingLeftWidth *2 +desHeight;
96100 [_gitButtons enumerateObjectsUsingBlock: ^(EaseGitButton *obj, NSUInteger idx, BOOL *stop) {
97- [obj setY: kPaddingLeftWidth *2 +desHeight];
101+ CGFloat diffY = ABS (CGRectGetMinY (obj.frame ) - gitBtnY);
102+ if (diffY > 1 ) {
103+ [obj setY: gitBtnY];
104+ }
98105 }];
99106}
100107
0 commit comments