You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
7.0 KiB

//
// WHomeFunCell.m
// tongxin
//
// Created by Apple on 2020/4/8.
// Copyright © 2020 xTT. All rights reserved.
//
#import "WHomeFunCell.h"
@interface WHomeFunCell ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
@property (nonatomic, strong) NSArray * myDataTitleImageArr;
@property (nonatomic, strong) NSArray * myDataSource;
@end
@implementation WHomeFunCell
- (NSArray *)myDataSource{
if (!_myDataSource) {
_myDataSource = @[
@"电话本",
@"微聊",
@"打电话",
@"更多"
];
}
return _myDataSource;
}
- (NSArray *)myDataTitleImageArr{
if (!_myDataTitleImageArr) {
_myDataTitleImageArr = @[
@"icon_phonebook",
@"icon_small_talk",
@"icon_answer",
@"icon_more"
];
}
return _myDataTitleImageArr;
}
-(void)setFuncArrTitles:(NSArray*)funcArrTitles TitleImage:(NSArray*)array{
self.myDataSource = funcArrTitles;
self.myDataTitleImageArr = array;
[self.funCollectionView reloadData];
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
self.funCollectionView.contentSize = CGSizeMake(ScreenWidth-12*2, 0);
[self.funCollectionView setCornerRadius:5];
self.funCollectionView.dataSource = self;
self.funCollectionView.delegate = self;
self.funCollectionView.contentOffset = CGPointMake(0, 0);
self.funCollectionView.bounces = NO;
self.funCollectionView.scrollEnabled = NO;
[self.funCollectionView registerNib:[UINib nibWithNibName:@"WatchFunctionCell" bundle:nil] forCellWithReuseIdentifier:@"WatchFunctionCell"];
}
#pragma collectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
// 功能列表
return self.myDataSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// 功能的 collection
WatchFunctionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WatchFunctionCell"
forIndexPath:indexPath];
NSString *title = self.myDataSource[indexPath.item];
NSString *BtnImageUrl = self.myDataTitleImageArr[indexPath.item];
[cell.watchFunctionImgView setImage:[UIImage imageNamed:BtnImageUrl]];
cell.heightNSLC.constant = 32;
cell.widthNSLC.constant = 32;
cell.watchFunctionLabel.text = title;
cell.watchFunctionCornerMark.font = [UIFont systemFontOfSize:15];
[cell.watchFunctionCornerMark setBackgroundColor:[UIColor redColor]];
[cell.watchFunctionCornerMark setHidden: YES];
if ([title isEqualToString:@"微聊"]) {
self.chatCell = cell;
if(self.chatCellSelectBack){
self.chatCellSelectBack(cell);
}
}
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return (CGSize){((SWIDTH-12*2)/ _myDataSource.count/*4.0*/), 75};
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
//设置水平间距 (同一行的cell的左右间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}
//垂直间距 (同一列cell上下间距)
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *title = self.myDataSource[indexPath.item];
if([title isEqualToString:@"电话本"] || [title isEqualToString:@"管理员"]){
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"ContactsViewController"];
[self.getViewController.navigationController pushViewController:vc animated:YES];
}else if([title isEqualToString:@"视频通话"]) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *vc =[sb instantiateViewControllerWithIdentifier:@"VideoCallViewController"];
[self.getViewController.navigationController pushViewController:vc animated:YES];
}else if([title isEqualToString:@"微聊"]) {
[self.getViewController performSegueWithIdentifier:@"goChatVC" sender:nil];
}else if([title isEqualToString:@"打电话"]) {
[cUser.cDevice makePhoneCallWithViewController:self.getViewController];
}else if([title isEqualToString:@"更多"]) {
[self.getViewController performSegueWithIdentifier:@"goMoreGN" sender:nil];
}
// switch (indexPath.item) {
// case 0:{ // 电话本 / 视频通话
//
// if([title isEqualToString:@"电话本"] || [title isEqualToString:@"管理员"]){
// UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"ContactsViewController"];
// [self.getViewController.navigationController pushViewController:vc animated:YES];
// }else{
// UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
// UIViewController *vc =[sb instantiateViewControllerWithIdentifier:@"VideoCallViewController"];
// [self.getViewController.navigationController pushViewController:vc animated:YES];
// }
// }
// break;
// case 1:{
// //微聊
// [self.getViewController performSegueWithIdentifier:@"goChatVC" sender:nil];
// }
// break;
// case 2:{ //打电话
// [cUser.cDevice makePhoneCallWithViewController:self.getViewController];
// }
// break;
// case 3:{ // 更多
// [self.getViewController performSegueWithIdentifier:@"goMoreGN" sender:nil];
// }
// break;
// default:
// break;
// }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end