Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,13 @@
//
// UMComForumFindViewController.h
// UMCommunity
//
// Created by umeng on 15/11/17.
// Copyright © 2015年 Umeng. All rights reserved.
//
#import "UMComViewController.h"
@interface UMComDiscoverViewController : UMComViewController
@end
@@ -0,0 +1,460 @@
//
// UMComForumFindViewController.m
// UMCommunity
//
// Created by umeng on 15/11/17.
// Copyright © 2015年 Umeng. All rights reserved.
//
#import "UMComDiscoverViewController.h"
#import "UMComFindTableViewCell.h"
#import "UMComProfileSettingController.h"
#import "UIViewController+UMComAddition.h"
#import <UMCommunitySDK/UMComSession.h>
#import "UMComUserInfoBar.h"
#import "UMComLoginManager.h"
#import <UMComDataStorage/UMComUnReadNoticeModel.h>
#import "UMComResouceDefines.h"
#import "UMComUserTableViewController.h"
#import <UMComFoundation/UMComKit+Color.h>
#import <UMComFoundation/UMComDefines.h>
#import "UMComNotificationMacro.h"
@interface UMComDiscoverViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UIButton *rightButton;
@property (nonatomic, strong) UIView *systemNotificationView;
@property (nonatomic, strong) UIView *userMessageView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UMComUserInfoBar *userInfoBar;
@end
@implementation UMComDiscoverViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setForumUIBackButton];
[self setForumUITitle:UMComLocalizedString(@"um_com_find", @"我的")];
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
self.tableView.delegate = self;
self.tableView.dataSource = self;
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
[self.tableView registerNib:[UINib nibWithNibName:@"UMComFindTableViewCell" bundle:nil] forCellReuseIdentifier:@"FindTableViewCell"];
self.tableView.rowHeight = 55.0f;
if (UMCom_Current_System_Version >= 7.0 && UMCom_Current_System_Version < 8) {
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}else{
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
[self.view addSubview:self.tableView];
UIButton *menuItemButton = [UIButton buttonWithType:UIButtonTypeCustom];
[menuItemButton addTarget:self action:@selector(tranToSetting) forControlEvents:UIControlEventTouchUpInside];
[menuItemButton setImage:UMComImageWithImageName(@"um_setting_normal") forState:UIControlStateNormal];
[menuItemButton setImage:UMComImageWithImageName(@"um_setting_highlighted") forState:UIControlStateHighlighted];
menuItemButton.frame = CGRectMake(0.f, 0.f, 20.f, 20.f);
UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithCustomView:menuItemButton];
[self.navigationItem setRightBarButtonItem:menuItem];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNoticeItemViews) name:kUMComUnreadNotificationRefreshNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshMessageData:) name:UIApplicationWillEnterForegroundNotification object:nil];
[self refreshNoticeItemViews];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.rightButton removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)refreshMessageData:(id)sender
{
if (![[UMComSession sharedInstance] isLogin]) {
return;
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[[UMComSession sharedInstance] refreshConfigDataWithCompletion:^(NSDictionary *configData, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}];
}
- (void)refreshNoticeItemViews
{
[self.tableView reloadData];
}
- (UIView *)creatNoticeViewWithOriginX:(CGFloat)originX
{
CGFloat noticeViewWidth = 7;
UIView *itemNoticeView = [[UIView alloc]initWithFrame:CGRectMake(originX,0, noticeViewWidth, noticeViewWidth)];
itemNoticeView.backgroundColor = [UIColor redColor];
itemNoticeView.layer.cornerRadius = noticeViewWidth/2;
itemNoticeView.clipsToBounds = YES;
itemNoticeView.hidden = YES;
return itemNoticeView;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return 0;
} else if (section == 1) {
return 5;
} else {
return 5;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"FindTableViewCell";
UMComFindTableViewCell *cell = (UMComFindTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (indexPath.section == 0) {
} else if (indexPath.section == 1) {
switch (indexPath.row) {
case 0: {
cell.titleImageView.image = UMComImageWithImageName(@"um_notice_f");
cell.titleNameLabel.text = UMComLocalizedString(@"um_news_notice", @"我的消息");
UMComUnReadNoticeModel *unReadNotice = [UMComSession sharedInstance].unReadNoticeModel;
if (unReadNotice.totalNotiCount == 0) {
self.userMessageView.hidden = YES;
}else{
if (!self.userMessageView) {
CGFloat padding = 2;
CGFloat defaultNoticeViewOriginX = 115;
CGSize nameSize = [cell.titleNameLabel.text sizeWithFont:cell.titleNameLabel.font];
CGFloat noticeViewOriginX = cell.titleNameLabel.frame.origin.x + nameSize.width + padding;
if (noticeViewOriginX >= cell.contentView.bounds.size.width) {
//大于cell的宽度就减去padding
noticeViewOriginX = cell.contentView.bounds.size.width - padding;
}
else if (noticeViewOriginX <= 0)
{
//小于0就用默认
noticeViewOriginX = defaultNoticeViewOriginX;
}
else{}
self.userMessageView = [self creatNoticeViewWithOriginX:noticeViewOriginX];
self.userMessageView.center = CGPointMake(self.userMessageView.center.x, cell.titleNameLabel.frame.origin.y+11);
[cell.contentView addSubview:self.userMessageView];
} else {
if (self.userMessageView.superview != cell.contentView) {
[self.userMessageView removeFromSuperview];
[cell addSubview:self.userMessageView];
}
}
self.userMessageView.hidden = NO;
}
}
break;
case 1: {
cell.titleImageView.image = UMComImageWithImageName(@"um_fav+");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_user_collection", @"我的收藏");
}
break;
case 2: {
cell.titleImageView.image = UMComImageWithImageName(@"um_friend");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_friend", @"好友圈");
}
break;
case 3: {
// 我关注的
cell.titleImageView.image = UMComImageWithImageName(@"um_follow_topic");
cell.titleNameLabel.text = UMComLocalizedString(@"um_follow_topic", @"我关注的话题");
}
break;
case 4: {
// 我的图册
cell.titleImageView.image = UMComImageWithImageName(@"um_my_gallery");
cell.titleNameLabel.text = UMComLocalizedString(@"um_my_gallery", @"我的图册");
}
break;
default:
break;
}
} else {
switch (indexPath.row) {
case 0: {
cell.titleImageView.image = UMComImageWithImageName(@"um_near");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_nearbyRecommend", @"附近内容");
}
break;
case 1: {
cell.titleImageView.image = UMComImageWithImageName(@"um_nearbyuser");
cell.titleNameLabel.text = UMComLocalizedString(@"um_nearbyuser", @"附近用户");
}
break;
case 2: {
cell.titleImageView.image = UMComImageWithImageName(@"um_newcontent");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_newcontent", @"实时内容");
}
break;
case 3: {
cell.titleImageView.image = UMComImageWithImageName(@"user_recommend");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_user_recommend", @"用户推荐");
}
break;
case 4: {
cell.titleImageView.image = UMComImageWithImageName(@"topic_recommend");
cell.titleNameLabel.text = UMComLocalizedString(@"topic_recommend", @"话题推荐");
}
break;
default:
break;
}
}
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
UIEdgeInsets edge = UIEdgeInsetsMake(tableView.rowHeight - 1, 15, 0, 0);
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:edge];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:edge];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return 91.f;
} else if (section == 1) {
return 31.0f;
}else {
return 31.0f;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 0) {
NSArray *xibs = [[NSBundle mainBundle] loadNibNamed:@"UMComUserInfoBar" owner:self options:nil];
self.userInfoBar = xibs[0];
[_userInfoBar refresh];
[_userInfoBar addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(prepareToUserCenter)]];
return _userInfoBar;
} else if (section == 1) {
return [self headViewWithTitle:UMComLocalizedString(@"um_com_find", @"我的") viewHeight:31];
} else {
return [self headViewWithTitle:UMComLocalizedString(@"um_com_recommend", @"推荐") viewHeight:31];
}
}
- (UIView *)headViewWithTitle:(NSString *)title viewHeight:(CGFloat)viewHeight
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, viewHeight)];
view.backgroundColor = UMComColorWithHexString(@"#F5F6FA");
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(13, 0, 50, 30)];
CGPoint center = label.center;
center.y = view.frame.size.height / 2.f;
label.center = center;
label.backgroundColor = [UIColor clearColor];
label.text = title;
label.textColor = UMComColorWithHexString(FontColorGray);
label.font = UMComFontNotoSansLightWithSafeSize(13.f);
[view addSubview:label];
UIView *bottomLine = [[UIView alloc]initWithFrame:CGRectMake(0,viewHeight-0.5,view.frame.size.width,0.5)];
bottomLine.backgroundColor = UMComTableViewSeparatorColor;
[view addSubview:bottomLine];
if ([[UIDevice currentDevice].systemVersion floatValue] < 8.0) {
UIView *topLine = [[UIView alloc]initWithFrame:CGRectMake(0,0,view.frame.size.width,0.5)];
topLine.backgroundColor = UMComTableViewSeparatorColor;
[view addSubview:topLine];
}
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
} else if (indexPath.section == 1) {
[UMComLoginManager performLogin:self completion:^(id responseObject, NSError *error) {
if (error) {
return;
}
switch (indexPath.row) {
case 0:
{
self.userMessageView.hidden = YES;
[self tranToUsersNotice];
}
break;
case 1:
[self tranToUsersFavourites];
break;
case 2:
[self tranToCircleFriends];
break;
case 3:
[self tranToFollowedTopic];
break;
case 4:
[self tranToAlbum];
break;
default:
break;
}
}];
}else if(indexPath.section == 2){
switch (indexPath.row) {
case 0:
{
[UMComLoginManager performLogin:self completion:^(id responseObject, NSError *error) {
if (!error) {
[self tranToNearby];
}
}];
}
break;
case 1:
{
[UMComLoginManager performLogin:self completion:^(id responseObject, NSError *error) {
if (!error) {
[self tranToNearbyUsers];
}
}];
}
break;
case 2:
[self tranToRealTimeFeeds];
break;
case 3:
[self tranToRecommendUsers];
break;
case 4:
[self tranToRecommendTopics];
break;
default:
break;
}
}
}
- (void)prepareToUserCenter
{
if ([UMComLoginManager isLogin]) {
[self tranToUserCenter];
} else {
__weak typeof(self) ws = self;
[UMComLoginManager performLogin:self completion:^(id responseObject, NSError *error) {
if (!error) {
[ws.userInfoBar refresh];
}
}];
}
}
- (void)tranToCircleFriends
{
}
- (void)tranToFollowedTopic
{
}
- (void)tranToAlbum
{
}
- (void)tranToNearby
{
}
- (void)tranToNearbyUsers
{
}
- (void)tranToRealTimeFeeds
{
}
- (void)tranToRecommendUsers
{
}
- (void)tranToRecommendTopics
{
}
- (void)tranToUsersFavourites
{
}
- (void)tranToUsersNotice
{
}
- (void)tranToSetting
{
__weak typeof(self) ws = self;
[UMComLoginManager performLogin:self completion:^(id responseObject, NSError *error) {
if (!error) {
UMComProfileSettingController *settingVc = [[UMComProfileSettingController alloc]initWithNibName:@"UMComProfileSettingController" bundle:nil];
[ws.navigationController pushViewController:settingVc animated:YES];
}
}];
}
- (void)tranToUserCenter
{
}
@end
@@ -0,0 +1,17 @@
//
// UMComFindTableViewCell.h
// UMCommunity
//
// Created by umeng on 15-3-31.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UMComTableViewCell.h"
@interface UMComFindTableViewCell : UMComTableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *titleImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleNameLabel;
@end
@@ -0,0 +1,37 @@
//
// UMComFindTableViewCell.m
// UMCommunity
//
// Created by umeng on 15-3-31.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import "UMComFindTableViewCell.h"
#import "UMComResouceDefines.h"
#import <UMComFoundation/UMComKit+Color.h>
@implementation UMComFindTableViewCell
- (void)awakeFromNib {
// Initialization code
self.titleNameLabel.font = UMComFontNotoSansLightWithSafeSize(17);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)drawRect:(CGRect)rect
{
UIColor *color = UMComColorWithHexString(UMCom_Feed_BgColor);
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat height = 2;
CGRect drawFrame = CGRectMake(15, rect.size.height - height, rect.size.width-15, height);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, drawFrame);
}
@end
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="FindTableViewCell" id="KGk-i7-Jjw" customClass="UMComFindTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="59.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="26Z-cq-Jxv">
<rect key="frame" x="10" y="16" width="25" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="jmT-sd-hqO">
<rect key="frame" x="45" y="10" width="267" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="titleImageView" destination="26Z-cq-Jxv" id="0uX-KH-F1O"/>
<outlet property="titleNameLabel" destination="jmT-sd-hqO" id="11G-NX-9Hb"/>
</connections>
<point key="canvasLocation" x="56" y="146"/>
</tableViewCell>
</objects>
</document>
@@ -0,0 +1,25 @@
//
// UMComUserInfoBar.h
// UMCommunity
//
// Created by umeng on 1/21/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UMComImageView.h"
@interface UMComUserInfoBar : UIView
@property (weak, nonatomic) IBOutlet UMComImageView *avatar;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *status;
@property (weak, nonatomic) IBOutlet UILabel *follower;
@property (weak, nonatomic) IBOutlet UILabel *folowing;
@property (weak, nonatomic) IBOutlet UILabel *score;
@property (weak, nonatomic) IBOutlet UILabel *loginTip;
@property (weak, nonatomic) IBOutlet UIImageView *accessoryView;
- (void)refresh;
@end
@@ -0,0 +1,295 @@
//
// UMComUserInfoBar.m
// UMCommunity
//
// Created by umeng on 1/21/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import "UMComUserInfoBar.h"
#import "UMComResouceDefines.h"
#import <UMCommunitySDK/UMComSession.h>
#import <UMComDataStorage/UMComUser.h>
#import <UMComDataStorage/UMComImageUrl.h>
#import "UMComMedalImageView.h"
#import <UMComDataStorage/UMComMedal.h>
#import <UMComFoundation/UMComKit+Color.h>
const CGFloat g_UMComUserInfoBar_SpaceBetweenNameAndMedal = 5;//勋章和名字的间距
@interface UMComUserInfoBar ()<UMComImageViewDelegate>
//单个勋章显示
//@property(nonatomic,strong)UMComMedalImageView* medalView;
//多勋章布局
@property(nonatomic,assign)NSInteger curMedalCount;//勋章的数量(最大5个)
@property(nonatomic,strong)NSMutableArray* medalViewArray;//包含勋章控件
-(void) createMedalViews;
-(void) requestIMGForMedalViews:(UMComUser*)user;
-(void) clearRequestForMedalViews;
-(CGSize)computeMedalViewSize:(UMComMedalImageView*)medalView;
-(void) layoutMedalViews;
@end
@implementation UMComUserInfoBar
- (void)awakeFromNib
{
[super awakeFromNib];
//单个勋章显示
// self.medalView = [[UMComMedalImageView alloc] initWithFrame:CGRectMake(0, 0, [UMComMedalImageView defaultWidth], [UMComMedalImageView defaultHeight])];
// self.medalView.contentMode = UIViewContentModeScaleAspectFit;
// [self addSubview:self.medalView];
[self createMedalViews];
self.name.textColor = UMComColorWithHexString(@"#666666");
self.name.font = UMComFontNotoSansLightWithSafeSize(15);
}
- (void)refresh
{
if ([UMComSession sharedInstance].isLogin) {
UMComUser *user = [UMComSession sharedInstance].loginUser;
_name.text = user.name;
//单勋章布局--begin
/*
if (user.medal_list.count > 0) {
UMComMedal* umcomMedal = (UMComMedal*)user.medal_list.firstObject;
if (umcomMedal && umcomMedal.icon_url) {
[self.medalView setImageURL:[NSURL URLWithString:umcomMedal.icon_url] placeholderImage:nil];
//布局勋章和name的坐标
CGFloat nameWidth = 0;
CGFloat maxWidth = self.accessoryView.frame.origin.x - self.name.frame.origin.x- [UMComMedalImageView defaultWidth] - g_UMComUserInfoBar_SpaceBetweenNameAndMedal;
CGSize size = [user.name sizeWithFont:UMComFontNotoSansLightWithSafeSize(15)];
if (size.width >= maxWidth) {
nameWidth = maxWidth;
}
else{
nameWidth = size.width;
}
CGRect nameFrame = self.name.frame;
nameFrame.size.width = nameWidth;
self.name.frame = nameFrame;
CGRect medalFrame = self.medalView.frame;
medalFrame.origin.x = self.name.frame.origin.x + self.name.frame.size.width+g_UMComUserInfoBar_SpaceBetweenNameAndMedal;
medalFrame.origin.y = self.name.frame.origin.y;
self.medalView.frame = medalFrame;
}
}
*/
//单勋章布局--end
//多勋章布局----begin
if (user.medal_list.count > 0) {
[self clearRequestForMedalViews];
[self requestIMGForMedalViews:user];
}
//多勋章布局----end
_status.text = user.level_title;
_status.layer.borderWidth = .5f;
_status.layer.borderColor = UMComColorWithHexString(@"34C035").CGColor;
_follower.text = [NSString stringWithFormat:UMComLocalizedString(@"um_com_funCount_template", @"粉丝 %@"), countString(user.fans_count)];
_folowing.text = [NSString stringWithFormat:UMComLocalizedString(@"um_com_followingCount_template", @"关注 %@"), countString(user.following_count)];
_score.text = [NSString stringWithFormat:UMComLocalizedString(@"um_com_scoreCount_template", @"积分 %@"), countString(user.point)];
[_avatar setImageURL:[user.icon_url small_url_string] placeHolderImage:UMComImageWithImageName(@"um_forum_post_default")];
[self hideInfoSubviews:NO];
_loginTip.hidden = YES;
} else {
[self hideInfoSubviews:YES];
_loginTip.hidden = NO;
[_avatar setImage:UMComImageWithImageName(@"um_forum_post_default")];
}
}
- (void)hideInfoSubviews:(BOOL)hide
{
_name.hidden = hide;
_status.hidden = hide;
_follower.hidden = hide;
_folowing.hidden = hide;
_score.hidden = hide;
// _medalView.hidden = hide;
if (hide) {
[self clearRequestForMedalViews];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
#pragma mark - 勋章相关
-(void) createMedalViews
{
//创建默认的medalViewArray队列
self.medalViewArray = [NSMutableArray arrayWithCapacity:[UMComMedalImageView maxMedalCount]];
//创建勋章
for(NSInteger i = 0; i < [UMComMedalImageView maxMedalCount]; i++)
{
UMComMedalImageView* medalView = [[UMComMedalImageView alloc] initWithFrame:CGRectMake(0, 0, [UMComMedalImageView defaultWidth], [UMComMedalImageView defaultHeight])];
medalView.tag = i;
medalView.contentMode = UIViewContentModeScaleAspectFit;
[self.medalViewArray addObject:medalView];
[self addSubview:medalView];
}
}
-(void) requestIMGForMedalViews:(UMComUser*)user
{
if (user.medal_list.count > 0) {
//确认当前勋章不能超过[UMComMedalImageView maxMedalCount]
self.curMedalCount = user.medal_list.count;
if (self.curMedalCount > [UMComMedalImageView maxMedalCount]) {
self.curMedalCount = [UMComMedalImageView maxMedalCount];
}
for(int i = 0;i < self.curMedalCount; i++)
{
UMComMedalImageView* medalView = self.medalViewArray[i];
if (medalView) {
medalView.hidden = NO;
UMComMedal* umcomMedal = (UMComMedal*)user.medal_list[i];
if (umcomMedal && umcomMedal.icon_url) {
medalView.imageLoaderDelegate = nil;
medalView.isAutoStart = YES;
[medalView setImageURL:[NSURL URLWithString:umcomMedal.icon_url] placeholderImage:nil];
medalView.imageLoaderDelegate = self;
}
else{
medalView.hidden = YES;
}
}
}
[self layoutMedalViews];
}
}
-(void) clearRequestForMedalViews
{
for(int i = 0;i < self.medalViewArray.count; i++)
{
UMComMedalImageView* medalView = self.medalViewArray[i];
if (medalView) {
medalView.hidden = YES;
medalView.imageLoaderDelegate = nil;
}
}
}
-(CGSize)computeMedalViewSize:(UMComMedalImageView*)medalView
{
if (!medalView) {
return CGSizeMake(0, 0);
}
//先确定勋章图片的宽度和高度;
CGFloat medalWidth = [UMComMedalImageView defaultWidth];
CGFloat medalHeight = [UMComMedalImageView defaultHeight];
CGSize cellSize = self.bounds.size;
if (medalView.image) {
CGSize tempSize = medalView.image.size;
if (tempSize.height <= medalHeight) {
medalHeight = tempSize.height;
}
else{
//目前只是简单的判断图片的高度是否超过self.nameLabel.frame的高度
if (tempSize.height < self.name.frame.size.height) {
medalHeight = tempSize.height;
}
else
{
medalHeight = self.name.frame.size.height;
}
}
if (tempSize.width <= medalWidth) {
medalWidth = tempSize.width;
}
else{
//根据图片的宽高比,算勋章的宽度
medalWidth = medalHeight * tempSize.width / tempSize.height;
if (medalWidth >= cellSize.width) {
//如果宽度大于cell的宽度就设置为默认值(此处只是简单判断)
medalWidth = [UMComMedalImageView defaultWidth];
}
}
}
medalView.bounds = CGRectMake(0, 0, medalWidth, medalHeight);
return medalView.bounds.size;
}
-(void) layoutMedalViews
{
//先确定勋章图片的宽度和高度
CGFloat totalMedalWidth = 0;
for (int i = 0; i < self.curMedalCount; i++) {
//先计算图片的宽高
UMComMedalImageView* medalView = self.medalViewArray[i];
if (medalView) {
CGSize medalViewSize = [self computeMedalViewSize:medalView];
totalMedalWidth += medalViewSize.width + [UMComMedalImageView spaceBetweenMedalViews];
}
}
//计算nameLabel的宽度
CGFloat nameLabelWidth = 0;
CGFloat nameLabelMaxWidth = self.bounds.size.width - self.name.frame.origin.x - totalMedalWidth - 10;
CGSize nameLabelSize = [self.name.text sizeWithFont:self.name.font];
if (nameLabelSize.width > nameLabelMaxWidth) {
nameLabelWidth = nameLabelMaxWidth;
}
else{
nameLabelWidth = nameLabelSize.width;
}
//确定nameLabel的范围
CGRect nameLabelFrame = self.name.frame;
nameLabelFrame.size.width = nameLabelWidth;
self.name.frame = nameLabelFrame;
//确定medalViews的范围
CGFloat offsetX = self.name.frame.origin.x + self.name.frame.size.width + 5;
CGFloat offsetY = self.name.frame.origin.y;
for (int i = 0; i < self.curMedalCount; i++) {
UMComMedalImageView* medalView = self.medalViewArray[i];
if (medalView) {
CGRect medalViewFrame = medalView.frame;
medalViewFrame.origin.x = offsetX;
medalViewFrame.origin.y = offsetY;
medalView.frame = medalViewFrame;
offsetX += medalViewFrame.size.width + [UMComMedalImageView spaceBetweenMedalViews];
}
}
}
- (void)umcomImageViewLoadedImage:(UMComImageView *)imageView
{
[self layoutMedalViews];
}
@end
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="14F1605" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="UMComUserInfoBar">
<rect key="frame" x="0.0" y="0.0" width="510" height="91"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="IW5-50-zb3" customClass="UMComImageView">
<rect key="frame" x="15" y="16" width="60" height="60"/>
<constraints>
<constraint firstAttribute="height" constant="60" id="bHG-Qi-Kjn"/>
<constraint firstAttribute="width" constant="60" id="fTn-xP-h0c"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="30"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mcd-Jr-OHp">
<rect key="frame" x="86" y="29" width="7" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.40000000000000002" green="0.40000000000000002" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GKT-J8-uiK">
<rect key="frame" x="103" y="30" width="5" height="16"/>
<constraints>
<constraint firstAttribute="height" constant="16" id="1r1-5D-LKP"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="9"/>
<color key="textColor" red="0.20392156862745098" green="0.75294117647058822" blue="0.20784313725490194" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.borderWidth">
<integer key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="layer.borderColor">
<color key="value" red="0.20392156862745098" green="0.75294117647058822" blue="0.20784313725490194" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h6G-0d-msB">
<rect key="frame" x="86" y="57" width="6" height="15"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="0.6470588235294118" green="0.6470588235294118" blue="0.6470588235294118" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bWH-D0-UTD">
<rect key="frame" x="102" y="57" width="6" height="15"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="0.6470588235294118" green="0.6470588235294118" blue="0.6470588235294118" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mqn-mQ-01b">
<rect key="frame" x="118" y="57" width="6" height="15"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="0.6470588235294118" green="0.6470588235294118" blue="0.6470588235294118" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="立即登录" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="o8g-O3-l18" userLabel="loginTip">
<rect key="frame" x="86" y="36" width="64" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="UMComSDKResources.bundle/images/um_forum_arrow_gray.png" translatesAutoresizingMaskIntoConstraints="NO" id="7i2-4N-dvW">
<rect key="frame" x="482" y="39" width="8" height="13"/>
<constraints>
<constraint firstAttribute="width" constant="8" id="Eyx-Sc-aGj"/>
<constraint firstAttribute="height" constant="13" id="uKG-f8-CNs"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="mqn-mQ-01b" firstAttribute="leading" secondItem="bWH-D0-UTD" secondAttribute="trailing" constant="10" id="5Ne-wj-fw0"/>
<constraint firstItem="o8g-O3-l18" firstAttribute="leading" secondItem="IW5-50-zb3" secondAttribute="trailing" constant="11" id="Brm-Pc-1lg"/>
<constraint firstItem="h6G-0d-msB" firstAttribute="top" secondItem="mcd-Jr-OHp" secondAttribute="bottom" constant="10" id="Drf-zB-qew"/>
<constraint firstItem="GKT-J8-uiK" firstAttribute="leading" secondItem="mcd-Jr-OHp" secondAttribute="trailing" constant="10" id="E9z-aZ-Uzx"/>
<constraint firstItem="mqn-mQ-01b" firstAttribute="top" secondItem="h6G-0d-msB" secondAttribute="top" id="GZK-DW-eo1"/>
<constraint firstItem="7i2-4N-dvW" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="Jp4-F3-pFz"/>
<constraint firstItem="h6G-0d-msB" firstAttribute="leading" secondItem="mcd-Jr-OHp" secondAttribute="leading" id="Ngv-cf-8bj"/>
<constraint firstItem="o8g-O3-l18" firstAttribute="centerY" secondItem="IW5-50-zb3" secondAttribute="centerY" id="OcU-Sm-vZz"/>
<constraint firstAttribute="trailing" secondItem="7i2-4N-dvW" secondAttribute="trailing" constant="20" id="PHA-pI-tNc"/>
<constraint firstItem="GKT-J8-uiK" firstAttribute="centerY" secondItem="mcd-Jr-OHp" secondAttribute="centerY" id="PhS-Ld-cwj"/>
<constraint firstItem="IW5-50-zb3" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="15" id="RK8-4l-fOF"/>
<constraint firstItem="mcd-Jr-OHp" firstAttribute="leading" secondItem="IW5-50-zb3" secondAttribute="trailing" constant="11" id="V6e-lr-7Ks"/>
<constraint firstItem="bWH-D0-UTD" firstAttribute="top" secondItem="h6G-0d-msB" secondAttribute="top" id="VPL-L7-41Z"/>
<constraint firstItem="mcd-Jr-OHp" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="29" id="mM7-NZ-ulY"/>
<constraint firstItem="IW5-50-zb3" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="tk8-DP-crZ"/>
<constraint firstItem="bWH-D0-UTD" firstAttribute="leading" secondItem="h6G-0d-msB" secondAttribute="trailing" constant="10" id="uU1-ct-EjW"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="accessoryView" destination="7i2-4N-dvW" id="E3I-rc-4qW"/>
<outlet property="avatar" destination="IW5-50-zb3" id="Rya-Wl-W9f"/>
<outlet property="follower" destination="h6G-0d-msB" id="0cE-R0-9wO"/>
<outlet property="folowing" destination="bWH-D0-UTD" id="hHj-Wa-nLc"/>
<outlet property="loginTip" destination="o8g-O3-l18" id="9h7-au-byY"/>
<outlet property="name" destination="mcd-Jr-OHp" id="R3Y-Gg-CkW"/>
<outlet property="score" destination="mqn-mQ-01b" id="odE-LQ-66L"/>
<outlet property="status" destination="GKT-J8-uiK" id="Jd6-vb-24k"/>
</connections>
<point key="canvasLocation" x="302" y="289.5"/>
</view>
</objects>
<resources>
<image name="UMComSDKResources.bundle/images/um_forum_arrow_gray.png" width="150" height="150"/>
</resources>
</document>