66// Copyright © 2015年 Coding. All rights reserved.
77//
88
9+ #define kBaseCellHeight 110
10+
911#define kMRPRListCell_UserWidth 33.0
1012
1113#import " PRMRSearchCell.h"
14+ #import " NSString+Attribute.h"
1215
1316@interface PRMRSearchCell ()
14- @property (strong , nonatomic ) UIImageView *imgView;
15- @property (strong , nonatomic ) UILabel *titleLabel, *subTitleLabel;
17+ @property (strong , nonatomic ) UIImageView *imgView,*arrowIcon ;
18+ @property (strong , nonatomic ) UILabel *titleLabel, *subTitleLabel,*fromL,*toL ;
1619@end
1720
1821
19-
2022@implementation PRMRSearchCell
2123
2224- (id )initWithStyle : (UITableViewCellStyle)style reuseIdentifier : (NSString *)reuseIdentifier
@@ -39,8 +41,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
3941 make.centerY .equalTo (self.contentView );
4042 }];
4143 }
44+
4245 if (!_titleLabel) {
4346 _titleLabel = [UILabel new ];
47+ _titleLabel.textColor =[UIColor colorWithHexString: @" 0x222222" ];
48+ _titleLabel.font =[UIFont boldSystemFontOfSize: 14 ];
4449 [self .contentView addSubview: _titleLabel];
4550 [_titleLabel mas_makeConstraints: ^(MASConstraintMaker *make) {
4651 make.left .equalTo (_imgView.mas_right ).offset (12 );
@@ -49,6 +54,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
4954 make.height .mas_equalTo (20 );
5055 }];
5156 }
57+
5258 if (!_subTitleLabel) {
5359 _subTitleLabel = [UILabel new ];
5460 [self .contentView addSubview: _subTitleLabel];
@@ -57,6 +63,44 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
5763 make.bottom .equalTo (self.contentView .mas_bottom ).offset (-13 );
5864 }];
5965 }
66+
67+ if (!_fromL) {
68+ _fromL = [UILabel new ];
69+ [_fromL doBorderWidth: 0.5 color: [UIColor colorWithHexString: @" 0x4E90BF" ] cornerRadius: 2.0 ];
70+ _fromL.font = [UIFont systemFontOfSize: 12 ];
71+ _fromL.textColor = [UIColor colorWithHexString: @" 0x4E90BF" ];
72+ [self .contentView addSubview: _fromL];
73+ }
74+
75+ if (!_arrowIcon) {
76+ _arrowIcon = [UIImageView new ];
77+ _arrowIcon.image = [UIImage imageNamed: @" mrpr_icon_arrow" ];
78+ [self .contentView addSubview: _arrowIcon];
79+ }
80+
81+ if (!_toL) {
82+ _toL = [UILabel new ];
83+ [_toL doBorderWidth: 0.5 color: [UIColor colorWithHexString: @" 0x4E90BF" ] cornerRadius: 2.0 ];
84+ _toL.font = [UIFont systemFontOfSize: 12 ];
85+ _toL.textColor = [UIColor colorWithHexString: @" 0x4E90BF" ];
86+ [self .contentView addSubview: _toL];
87+ }
88+
89+
90+ [_fromL mas_makeConstraints: ^(MASConstraintMaker *make) {
91+ make.left .equalTo (_titleLabel);
92+ make.top .equalTo (_titleLabel.mas_bottom ).offset (15 );
93+ make.height .mas_equalTo (20 );
94+ }];
95+
96+ [_arrowIcon mas_makeConstraints: ^(MASConstraintMaker *make) {
97+ make.left .equalTo (_fromL.mas_right ).offset (10 );
98+ make.centerY .equalTo (_fromL);
99+ make.size .mas_equalTo (CGSizeMake (15 , 15 ));
100+ make.right .lessThanOrEqualTo (self.contentView ).offset (-kPaddingLeftWidth );
101+ }];
102+
103+
60104 }
61105 return self;
62106}
@@ -67,25 +111,41 @@ - (void)setCurMRPR:(MRPR *)curMRPR{
67111 return ;
68112 }
69113 [_imgView sd_setImageWithURL: [_curMRPR.author.avatar urlImageWithCodePathResize: 2 *kMRPRListCell_UserWidth ] placeholderImage: kPlaceholderMonkeyRoundWidth (2 *kMRPRListCell_UserWidth )];
70- _titleLabel.attributedText = [self attributeTitle ];
114+ _titleLabel.attributedText = [NSString getAttributeFromText: [_curMRPR.title stringByTrimmingCharactersInSet: [ NSCharacterSet whitespaceAndNewlineCharacterSet ]] emphasizeTag: @" em " emphasizeColor: [UIColor colorWithHexString: @" 0xE84D60 " ] ];
71115 _subTitleLabel.attributedText = [self attributeTail ];
72116
73- }
117+
118+ NSString *fromStr, *toStr;
119+ if (_curMRPR.isMR ) {
120+ fromStr = [NSString stringWithFormat: @" %@ " , _curMRPR.source_branch];
121+ toStr = [NSString stringWithFormat: @" %@ " , _curMRPR.target_branch];
122+ }else {
123+ fromStr = [NSString stringWithFormat: @" %@ : %@ " , _curMRPR.src_owner_name, _curMRPR.source_branch];
124+ toStr = [NSString stringWithFormat: @" %@ : %@ " , _curMRPR.des_owner_name, _curMRPR.target_branch];
125+ }
126+ NSString *totalStr = [NSString stringWithFormat: @" %@%@ " , fromStr, toStr];
127+ if ([totalStr getWidthWithFont: [UIFont systemFontOfSize: 12 ] constrainedToSize: CGSizeMake (CGFLOAT_MAX, 20 )] + 40 > kScreen_Width - 2 *kPaddingLeftWidth ) {
128+ [_toL mas_remakeConstraints: ^(MASConstraintMaker *make) {
129+ make.left .equalTo (_titleLabel);
130+ make.top .equalTo (_fromL.mas_bottom ).offset (15 );
131+ make.height .equalTo (_fromL);
132+ make.right .lessThanOrEqualTo (self.contentView ).offset (-kPaddingLeftWidth );
133+ }];
134+ }else {
135+ [_toL mas_remakeConstraints: ^(MASConstraintMaker *make) {
136+ make.left .equalTo (_arrowIcon.mas_right ).offset (10 );
137+ make.top .equalTo (_fromL);
138+ make.height .top .equalTo (_fromL);
139+ make.right .lessThanOrEqualTo (self.contentView ).offset (-kPaddingLeftWidth );
140+ }];
141+ }
142+ _fromL.attributedText = [NSString getAttributeFromText: [fromStr stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]] emphasizeTag: @" em" emphasizeColor: [UIColor colorWithHexString: @" 0xE84D60" ]];
143+ _toL.attributedText = [NSString getAttributeFromText: [fromStr stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]] emphasizeTag: @" em" emphasizeColor: [UIColor colorWithHexString: @" 0xE84D60" ]];
74144
75- - (NSAttributedString *)attributeTitle {
76- NSString *iidStr = [NSString stringWithFormat: @" #%@ " , _curMRPR.iid.stringValue? _curMRPR.iid.stringValue: @" " ];
77- NSString *titleStr = _curMRPR.title ? _curMRPR.title : @" " ;
78- NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc ] initWithString: [NSString stringWithFormat: @" %@ %@ " , iidStr, titleStr]];
79- [attrString addAttributes: @{NSFontAttributeName : [UIFont boldSystemFontOfSize: 14 ],
80- NSForegroundColorAttributeName : [UIColor colorWithHexString: @" 0x4E90BF" ]}
81- range: NSMakeRange (0 , iidStr.length)];
82- [attrString addAttributes: @{NSFontAttributeName : [UIFont boldSystemFontOfSize: 14 ],
83- NSForegroundColorAttributeName : [UIColor colorWithHexString: @" 0x222222" ]}
84- range: NSMakeRange (iidStr.length + 1 , titleStr.length)];
85- return attrString;
86145
87146}
88147
148+
89149- (NSAttributedString *)attributeTail {
90150 NSString *nameStr = _curMRPR.author .name ? _curMRPR.author .name : @" " ;
91151 NSString *timeStr = _curMRPR.created_at ? [_curMRPR.created_at stringDisplay_HHmm ]: @" " ;
@@ -101,7 +161,7 @@ - (NSAttributedString *)attributeTail{
101161
102162
103163+ (CGFloat)cellHeight {
104- return 70.0 ;
164+ return kBaseCellHeight ;
105165}
106166
107167@end
0 commit comments