zyds/ProductApp/ProductApp/ProductMain/首页/微信消息/view/WeiXinXXView.m

412 lines
14 KiB
Objective-C

//
// WeiXinXXView.m
// ProductApp
//
// Created by 工作 on 2025/3/29.
//
#import "WeiXinXXView.h"
#import "FSTextView.h"
#import "AlterSheetView.h"
#import "WYCamaImageTools.h"
#import "PickerAlterView.h"
#import "MNHeiPeiView.h"
#import "BaseViewController.h"
@interface WeiXinXXView ()<WYCamaImageToolsDelegate>
@property (nonatomic, strong) WYCamaImageTools *tools;
///
@property (nonatomic , strong) UIImageView *imgvback;
///
@property (nonatomic , strong) UITextField *fieldname;
@property (nonatomic , strong) UITextField *fieldtime;
@property (nonatomic , strong) UITextField *fieldnumber;
///
@property (nonatomic , strong) UITextView *textview;
@end
@implementation WeiXinXXView
-(id)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame])
{
UIScrollView *scvback = [[UIScrollView alloc] init];
[self addSubview:scvback];
[scvback mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.offset(0);
make.width.equalTo(self);
make.height.equalTo(self).offset(-TabHeight-20);
}];
UIView *viewbj = [[UIView alloc] init];
[viewbj setBackgroundColor:[UIColor whiteColor]];
[scvback addSubview:viewbj];
[viewbj mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.top.equalTo(scvback);
make.height.offset(86);
}];
_imgvback = [self drawImageCell:viewbj name:@"背景图片" isline:NO itag:0];
_imgvback.image = [UIImage imageNamed:@"dx_back"];
UIView *viewmc = [[UIView alloc] init];
[viewmc setBackgroundColor:[UIColor whiteColor]];
[scvback addSubview:viewmc];
[viewmc mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.equalTo(viewbj);
make.top.equalTo(viewbj.mas_bottom).offset(12);
make.height.offset(53);
}];
_fieldname = [self drawItemView:viewmc andtitle:@"对方名称" platch:@"请输入名称" isline:NO];
UIView *viewys = [[UIView alloc] init];
[viewys setBackgroundColor:[UIColor whiteColor]];
[scvback addSubview:viewys];
[viewys mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.equalTo(viewbj);
make.top.equalTo(viewmc.mas_bottom).offset(12);
make.height.offset(53);
}];
_fieldtime = [self drawItemView:viewys andtitle:@"微信消息延时" platch:@"请选择" tag:0];
_fieldtime.text = @"3秒钟";
UIView *viewsl = [[UIView alloc] init];
[viewsl setBackgroundColor:[UIColor whiteColor]];
[scvback addSubview:viewsl];
[viewsl mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.equalTo(viewbj);
make.top.equalTo(viewys.mas_bottom);
make.height.offset(53);
}];
_fieldnumber = [self drawItemView:viewsl andtitle:@"消息数量" platch:@"请输入数字" isline:YES];
[_fieldnumber setKeyboardType:UIKeyboardTypeNumberPad];
UIView *viewnr = [[UIView alloc] init];
[viewnr setBackgroundColor:[UIColor whiteColor]];
[scvback addSubview:viewnr];
[viewnr mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.equalTo(viewbj);
make.top.equalTo(viewsl.mas_bottom);
make.height.offset(147);
}];
_textview = [self drawTextView:viewnr];
[scvback mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(viewnr).offset(20);
}];
UIView *viewbottom = [[UIView alloc] init];
[viewbottom setBackgroundColor:[UIColor whiteColor]];
[self addSubview:viewbottom];
[viewbottom mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self);
make.height.offset(TabHeight+20);
}];
UIButton *btok = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH-32, 46)];
[btok setTitle:@"确定" forState:UIControlStateNormal];
[btok setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btok.titleLabel setFont:[UIFont systemFontOfSize:15]];
[btok.layer setMasksToBounds:YES];
[btok.layer setCornerRadius:23];
[viewbottom addSubview:btok];
[btok mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(16);
make.top.offset(9);
make.right.equalTo(viewbottom).offset(-16);
make.height.offset(46);
}];
[btok addTarget:self action:@selector(okAction) forControlEvents:UIControlEventTouchUpInside];
[Tools changedView:btok colors:@[(id)RGBCOLOR(119, 140, 245).CGColor,(id)RGBCOLOR(166, 121, 244).CGColor] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
}
return self;
}
-(UIImageView *)drawImageCell:(UIView *)view name:(NSString *)name isline:(BOOL)isline itag:(int)itag
{
UILabel *lbname = [[UILabel alloc] init];
[lbname setText:name];
[lbname setTextColor:RGBCOLOR(102, 102, 102)];
[lbname setTextAlignment:NSTextAlignmentLeft];
[lbname setFont:[UIFont systemFontOfSize:15]];
[view addSubview:lbname];
[lbname mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(16);
make.centerY.equalTo(view);
}];
UIImageView *imgvnext = [[UIImageView alloc] init];
[imgvnext setImage:[UIImage imageNamed:@"my_next"]];
[view addSubview:imgvnext];
[imgvnext mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.offset(20);
make.right.equalTo(view).offset(-9);
make.centerY.equalTo(view);
}];
UIImageView *imgvback = [[UIImageView alloc] init];
[imgvback setBackgroundColor:RGBCOLOR(237, 237, 237)];
[view addSubview:imgvback];
[imgvback mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.offset(58);
make.right.equalTo(imgvnext.mas_left).offset(-4);
make.centerY.equalTo(view);
}];
[imgvback setContentMode:UIViewContentModeScaleAspectFill];
[imgvback.layer setMasksToBounds:YES];
[imgvback.layer setCornerRadius:6];
UIButton *btimg = [[UIButton alloc] init];
[btimg setTag:itag];
[view addSubview:btimg];
[btimg mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(imgvback);
}];
[btimg addTarget:self action:@selector(imageAction:) forControlEvents:UIControlEventTouchUpInside];
if(isline)
{
UIView *viewline = [[UIView alloc] init];
[viewline setBackgroundColor:RGBCOLOR(238, 238, 238)];
[view addSubview:viewline];
[viewline mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(view);
make.left.offset(16);
make.right.equalTo(view).offset(-16);
make.height.offset(1);
}];
}
return imgvback;
}
-(UITextField *)drawItemView:(UIView *)view andtitle:(NSString *)title platch:(NSString *)platch tag:(int)tag
{
float f_w = [Tools getWidthWithText:title height:20 font:15]+5;
UILabel *lbname = [[UILabel alloc] init];
[lbname setText:title];
[lbname setTextColor:RGBCOLOR(102, 102, 102)];
[lbname setTextAlignment:NSTextAlignmentLeft];
[lbname setFont:[UIFont systemFontOfSize:15]];
[view addSubview:lbname];
[lbname mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(15);
make.centerY.equalTo(view);
make.width.offset(f_w);
}];
UITextField *field = [[UITextField alloc] init];
[field setTextColor:RGBCOLOR(102, 102, 102)];
[field setTextAlignment:NSTextAlignmentRight];
[field setFont:[UIFont systemFontOfSize:15]];
[view addSubview:field];
[field mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lbname.mas_right);
make.top.bottom.equalTo(view);
make.right.equalTo(view).offset(-33);
}];
[field setPlaceholder:platch];
UIImageView *imgvnext = [[UIImageView alloc] init];
[imgvnext setImage:[UIImage imageNamed:@"my_next"]];
[view addSubview:imgvnext];
[imgvnext mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(view).offset(-9);
make.centerY.equalTo(view);
make.width.height.offset(20);
}];
UIButton *btitem = [[UIButton alloc] init];
[view addSubview:btitem];
[btitem mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(field);
make.right.equalTo(view);
}];
[btitem setTag:tag];
[btitem addTarget:self action:@selector(itemAction:) forControlEvents:UIControlEventTouchUpInside];
UIView *viewline = [[UIView alloc] init];
[viewline setBackgroundColor:RGBCOLOR(238, 238, 238)];
[view addSubview:viewline];
[viewline mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(view);
make.left.offset(16);
make.right.equalTo(view).offset(-16);
make.height.offset(1);
}];
return field;
}
-(UITextField *)drawItemView:(UIView *)view andtitle:(NSString *)title platch:(NSString *)platch isline:(BOOL)isline
{
float f_w = [Tools getWidthWithText:title height:20 font:15]+5;
UILabel *lbname = [[UILabel alloc] init];
[lbname setText:title];
[lbname setTextColor:RGBCOLOR(102, 102, 102)];
[lbname setTextAlignment:NSTextAlignmentLeft];
[lbname setFont:[UIFont systemFontOfSize:15]];
[view addSubview:lbname];
[lbname mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(15);
make.centerY.equalTo(view);
make.width.offset(f_w);
}];
UITextField *field = [[UITextField alloc] init];
[field setTextColor:RGBCOLOR(102, 102, 102)];
[field setTextAlignment:NSTextAlignmentRight];
[field setFont:[UIFont systemFontOfSize:15]];
[view addSubview:field];
[field mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lbname.mas_right);
make.top.bottom.equalTo(view);
make.right.equalTo(view).offset(-16);
}];
[field setPlaceholder:platch];
if(isline)
{
UIView *viewline = [[UIView alloc] init];
[viewline setBackgroundColor:RGBCOLOR(238, 238, 238)];
[view addSubview:viewline];
[viewline mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(view);
make.left.offset(16);
make.right.equalTo(view).offset(-16);
make.height.offset(1);
}];
}
return field;
}
-(FSTextView *)drawTextView:(UIView *)view
{
UILabel *lbname = [[UILabel alloc] init];
[lbname setText:@"微信内容"];
[lbname setTextColor:RGBCOLOR(102, 102, 102)];
[lbname setTextAlignment:NSTextAlignmentLeft];
[lbname setFont:[UIFont systemFontOfSize:15]];
[view addSubview:lbname];
[lbname mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(15);
make.top.offset(16);
}];
FSTextView *textview = [[FSTextView alloc] init];
[textview setTextColor:RGBCOLOR(102, 102, 102)];
[textview setTextAlignment:NSTextAlignmentLeft];
[textview setFont:[UIFont systemFontOfSize:15]];
[textview setPlaceholder:@"请输入"];
[view addSubview:textview];
[textview mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(15);
make.top.offset(50);
make.bottom.equalTo(view).offset(-1);
make.right.equalTo(view).offset(-15);
}];
return textview;
}
-(void)imageAction:(UIButton *)sender
{
[self endEditing:YES];
_tools.isedit = NO;
[AlterSheetView showAlterSheetTitle:@"" bts:@[@"随机获取",@"拍照",@"相册中选择"] buttomTitle:@"取消" otherBtsColor:RGBCOLOR(92, 117, 248) otherColorTitles:@[@"随机获取"] backValue:^(NSInteger tag) {
NSLog(@"%ld",tag);
if(tag==1)
{
}
else if(tag==2)
{
[self.tools choosePicWithViewController:self.viewController chooseType:ChooseTypeTakePic];
}
else if(tag==3)
{
[self.tools choosePicWithViewController:self.viewController chooseType:ChooseTypeAlbum];
}
}];
}
-(void)itemAction:(UIButton *)sender
{
[self endEditing:YES];
[PickerAlterView showPickers:@[@"3秒钟",@"10秒钟",@"30秒钟",@"1分钟",@"2分钟",@"3分钟",@"5分钟",@"10分钟",@"30分钟"] title:@"选择时间" backValue:^(NSString * _Nonnull strback) {
self.fieldtime.text = strback;
}];
}
-(void)okAction
{
// if(!self.imgvback.image)
// {
// [HXHud showMessage:@"请选择背景图片" afterDelayType:0];
// return;
// }
// if(!self.imgvhead.image)
// {
// [HXHud showMessage:@"请选择对方头像" afterDelayType:0];
// return;
// }
// if(self.fieldname.text.length==0)
// {
// [HXHud showMessage:@"请输入对方名称" afterDelayType:0];
// return;
// }
// if(self.fieldnumber.text.length==0)
// {
// [HXHud showMessage:@"请输入消息数量" afterDelayType:0];
// return;
// }
// if(self.textview.text.length==0)
// {
// [HXHud showMessage:@"请输入微信内容" afterDelayType:0];
// return;
// }
//
NSString *strtime = self.fieldtime.text;
if([strtime containsString:@"秒钟"])
{
strtime=[strtime stringByReplacingOccurrencesOfString:@"秒钟" withString:@""];
}
else
{
strtime=[strtime stringByReplacingOccurrencesOfString:@"分钟" withString:@""];
strtime = [NSString stringWithFormat:@"%d",strtime.intValue*60];
}
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
BaseViewController *vc = (BaseViewController *)self.viewController;
[vc refShowStateBar:NO];
MNHeiPeiView *viewhp = [[MNHeiPeiView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT)];
[self.viewController.view addSubview:viewhp];
viewhp.time = strtime.intValue;
viewhp.imageBack = self.imgvback.image;
viewhp.strname = self.fieldname.text;
viewhp.strnumber = self.fieldnumber.text;
viewhp.strinfo = self.textview.text;
viewhp.type = 1;
}
#pragma mark - WYCamaImageToolsDelegate
-(void)didEndChoosePic:(UIImage *)image
{
self.imgvback.image = image;
}
- (WYCamaImageTools *)tools {
if (!_tools) {
_tools = [[WYCamaImageTools alloc] init];
_tools.delegate = self;
}return _tools;
}
@end