Initial commit
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// NTESCardPortraitCell.h
|
||||
// NIM
|
||||
//
|
||||
// Created by chris on 15/9/28.
|
||||
// Copyright © 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "NIMCommonTableViewCell.h"
|
||||
|
||||
@interface NTESCardPortraitCell : UITableViewCell<NIMCommonTableViewCell>
|
||||
|
||||
@end
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// NTESCardPortraitCell.m
|
||||
// NIM
|
||||
//
|
||||
// Created by chris on 15/9/28.
|
||||
// Copyright © 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESCardPortraitCell.h"
|
||||
#import "NIMAvatarImageView.h"
|
||||
#import "NIMCommonTableData.h"
|
||||
#import "UIView+NTES.h"
|
||||
#import "NTESSessionUtil.h"
|
||||
|
||||
|
||||
@interface NTESCardPortraitCell()
|
||||
|
||||
@property (nonatomic,strong) NIMAvatarImageView *avatar;
|
||||
|
||||
@property (nonatomic,strong) UILabel *nameLabel;
|
||||
|
||||
@property (nonatomic,strong) UILabel *nickNameLabel;
|
||||
|
||||
@property (nonatomic,strong) UILabel *accountLabel;
|
||||
|
||||
@property (nonatomic,strong) UIImageView *genderIcon;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NTESCardPortraitCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||||
if (self) {
|
||||
CGFloat avatarWidth = 55.f;
|
||||
_avatar = [[NIMAvatarImageView alloc] initWithFrame:CGRectMake(0, 0, avatarWidth, avatarWidth)];
|
||||
[self addSubview:_avatar];
|
||||
_nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_nameLabel.font = [UIFont systemFontOfSize:18.f];
|
||||
[self addSubview:_nameLabel];
|
||||
_nickNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_nickNameLabel.font = [UIFont systemFontOfSize:13.f];
|
||||
_nickNameLabel.textColor = [UIColor grayColor];
|
||||
[self addSubview:_nickNameLabel];
|
||||
_accountLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
_accountLabel.font = [UIFont systemFontOfSize:13.f];
|
||||
_accountLabel.textColor = [UIColor grayColor];
|
||||
[self addSubview:_accountLabel];
|
||||
_genderIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 14, 14)];
|
||||
[self addSubview:_genderIcon];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshData:(NIMCommonTableRow *)rowData tableView:(UITableView *)tableView{
|
||||
self.textLabel.text = rowData.title;
|
||||
self.detailTextLabel.text = rowData.detailTitle;
|
||||
NSString *uid = rowData.extraInfo;
|
||||
if ([uid isKindOfClass:[NSString class]]) {
|
||||
NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:uid];
|
||||
NIMKitInfo *info = [[NIMKit sharedKit] infoByUser:uid];
|
||||
self.nameLabel.text = info.showName ;
|
||||
self.accountLabel.text = [NSString stringWithFormat:@"帐号:%@",uid];
|
||||
[self.accountLabel sizeToFit];
|
||||
[self.avatar nim_setImageWithURL:[NSURL URLWithString:info.avatarUrlString] placeholderImage:info.avatarImage options:SDWebImageRetryFailed];
|
||||
if (user.userInfo.gender == NIMUserGenderMale) {
|
||||
_genderIcon.image = [UIImage imageNamed:@"icon_gender_male"];
|
||||
_genderIcon.hidden = NO;
|
||||
}
|
||||
else if(user.userInfo.gender == NIMUserGenderFemale) {
|
||||
_genderIcon.image = [UIImage imageNamed:@"icon_gender_female"];
|
||||
_genderIcon.hidden = NO;
|
||||
}
|
||||
else {
|
||||
_genderIcon.hidden = YES;
|
||||
}
|
||||
NSString *nickName = user.userInfo.nickName ? user.userInfo.nickName : @"";
|
||||
_nickNameLabel.hidden = !user.alias.length;
|
||||
_nickNameLabel.text = [NSString stringWithFormat:@"昵称:%@",nickName];
|
||||
[_nickNameLabel sizeToFit];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define AvatarLeft 30
|
||||
#define TitleAndAvatarSpacing 12
|
||||
#define TitleTop 22
|
||||
#define AccountBottom 22
|
||||
#define GenderIconAndTitleSpacing 12
|
||||
|
||||
- (void)layoutSubviews{
|
||||
[super layoutSubviews];
|
||||
self.avatar.left = AvatarLeft;
|
||||
self.avatar.centerY = self.height * .5f;
|
||||
|
||||
CGFloat scale = self.width / 320;
|
||||
CGFloat maxTextLabelWidth = 180 * scale;
|
||||
[self.nameLabel sizeToFit];
|
||||
self.nameLabel.width = MIN(self.nameLabel.width, maxTextLabelWidth);
|
||||
self.nameLabel.left = self.avatar.right + TitleAndAvatarSpacing;
|
||||
self.nameLabel.top = TitleTop;
|
||||
|
||||
if (self.nickNameLabel.hidden) {
|
||||
self.accountLabel.left = self.nameLabel.left;
|
||||
self.accountLabel.bottom = self.height - AccountBottom;
|
||||
}else{
|
||||
self.nickNameLabel.left = self.nameLabel.left;
|
||||
self.nickNameLabel.bottom = self.height - AccountBottom;
|
||||
self.accountLabel.left = self.nameLabel.left;
|
||||
self.accountLabel.centerY = (self.nickNameLabel.top + self.nameLabel.bottom) * .5f;
|
||||
}
|
||||
|
||||
self.genderIcon.left = self.nameLabel.right + GenderIconAndTitleSpacing;
|
||||
self.genderIcon.centerY = self.nameLabel.centerY;
|
||||
}
|
||||
|
||||
@end
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// NTESColorButtonCell.h
|
||||
// NIM
|
||||
//
|
||||
// Created by chris on 15/3/11.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "NIMCommonTableViewCell.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, ColorButtonCellStyle){
|
||||
ColorButtonCellStyleRed,
|
||||
ColorButtonCellStyleBlue,
|
||||
};
|
||||
|
||||
@class NTESColorButton;
|
||||
|
||||
@interface NTESColorButtonCell : UITableViewCell<NIMCommonTableViewCell>
|
||||
|
||||
@property (nonatomic,strong) NTESColorButton *button;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface NTESColorButton : UIButton
|
||||
|
||||
@property (nonatomic,assign) ColorButtonCellStyle style;
|
||||
|
||||
@end
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// NTESColorButtonCell.m
|
||||
// NIM
|
||||
//
|
||||
// Created by chris on 15/3/11.
|
||||
// Copyright (c) 2015年 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESColorButtonCell.h"
|
||||
#import "UIView+NTES.h"
|
||||
#import "NIMCommonTableData.h"
|
||||
|
||||
@interface NTESColorButtonCell()
|
||||
|
||||
@property (nonatomic,strong) NIMCommonTableRow *rowData;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NTESColorButtonCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||||
if (self) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
_button = [[NTESColorButton alloc] initWithFrame:CGRectZero];
|
||||
_button.size = [_button sizeThatFits:CGSizeMake(self.width, CGFLOAT_MAX)];
|
||||
_button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||
[self addSubview:_button];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshData:(NIMCommonTableRow *)rowData tableView:(UITableView *)tableView{
|
||||
self.rowData = rowData;
|
||||
[self.button setTitle:rowData.title forState:UIControlStateNormal];
|
||||
ColorButtonCellStyle style = [rowData.extraInfo integerValue];
|
||||
self.button.style = style;
|
||||
[self.button removeTarget:tableView.viewController action:NULL forControlEvents:UIControlEventTouchUpInside];
|
||||
if (rowData.cellActionName.length) {
|
||||
SEL action = NSSelectorFromString(rowData.cellActionName);
|
||||
[_button addTarget:tableView.viewController action:action forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
}
|
||||
|
||||
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
|
||||
if (self.rowData.cellActionName.length) {
|
||||
return [super hitTest:point withEvent:event];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews{
|
||||
[super layoutSubviews];
|
||||
_button.centerX = self.width * .5f;
|
||||
_button.centerY = self.height * .5f;
|
||||
}
|
||||
|
||||
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
|
||||
[_button setSelected:selected];
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
|
||||
[_button setHighlighted:highlighted];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NTESColorButton : UIButton
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self reset];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setStyle:(ColorButtonCellStyle)style{
|
||||
_style = style;
|
||||
[self reset];
|
||||
}
|
||||
|
||||
- (void)reset{
|
||||
NSString *imageNormalName = @"";
|
||||
NSString *imageHighLightName = @"";
|
||||
switch (self.style) {
|
||||
case ColorButtonCellStyleRed:
|
||||
imageNormalName = @"icon_cell_red_normal";
|
||||
imageHighLightName = @"icon_cell_red_pressed";
|
||||
break;
|
||||
case ColorButtonCellStyleBlue:
|
||||
imageNormalName = @"icon_cell_blue_normal";
|
||||
imageHighLightName = @"icon_cell_blue_pressed";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
UIImage *imageNormal = [[UIImage imageNamed:imageNormalName] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:UIImageResizingModeStretch];
|
||||
UIImage *imageHighLight = [[UIImage imageNamed:imageHighLightName] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:UIImageResizingModeStretch];
|
||||
[self setBackgroundImage:imageNormal forState:UIControlStateNormal];
|
||||
[self setBackgroundImage:imageHighLight forState:UIControlStateHighlighted];
|
||||
}
|
||||
|
||||
- (CGSize)sizeThatFits:(CGSize)size{
|
||||
return CGSizeMake(size.width - 20, 45);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user