//
|
// AdvertisePage.m
|
// istanbul
|
//
|
// Created by WindShan on 2017/6/14.
|
// Copyright © 2017年 WindShan. All rights reserved.
|
//
|
|
#import "AdvertisePage.h"
|
#import "WenDuPickerView.h"
|
#import "ASValueTrackingSlider.h"
|
#import "GloriaLabel.h"
|
#import "UITextView+Expand.h"
|
#import "NetworkSingleton.h"
|
#import "AdModel.h"
|
|
@interface AdvertisePage ()<ASValueTrackingSliderDelegate,ASValueTrackingSliderDataSource,UITextViewDelegate>
|
{
|
UITextView * adContextTextView;
|
UIButton * updownScrolBtn;
|
UIButton * rightleftScrolBtn;
|
AdModel * hotelSelModel;
|
}
|
|
@property (nonatomic, strong) ASValueTrackingSlider * trackingSlider;
|
@property (nonatomic, strong) GloriaLabel * adContextLabel;
|
@end
|
|
@implementation AdvertisePage
|
|
- (void)viewDidLoad
|
{
|
[super viewDidLoad];
|
|
self.navigationItem.title = @"发布广告";
|
[self setNavigationLeft:@"返回" sel:@selector(backAction)];
|
|
UIImageView * ad_context_bk = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, SCREEN_WIDTH-20, 148)];
|
ad_context_bk.image = [UIImage imageNamed:@"ad_context_bk"];
|
ad_context_bk.userInteractionEnabled = YES;
|
[self.view addSubview:ad_context_bk];
|
|
UIImageView * ad_context_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 16, 16)];
|
ad_context_tag.image = [UIImage imageNamed:@"ad_context_tag"];
|
[ad_context_bk addSubview:ad_context_tag];
|
|
_adContextLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(30, 2,100, 30)];
|
_adContextLabel.font = [UIFont systemFontOfSize:14];
|
_adContextLabel.textAlignment = UITextAlignmentLeft;
|
_adContextLabel.textColor = kUIColorFromRGB(0x00b744);
|
_adContextLabel.text = @"广告内容";
|
[ad_context_bk addSubview:_adContextLabel];
|
|
UIImageView * ad_context_line = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, ad_context_bk.frame.size.width-20, 1)];
|
ad_context_line.image = [UIImage imageNamed:@"ad_context_line"];
|
[ad_context_bk addSubview:ad_context_line];
|
|
adContextTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, 32, ad_context_bk.frame.size.width-20, 110)]; //初始化大小并自动释放
|
adContextTextView.textColor = [UIColor blackColor];//设置textview里面的字体颜色
|
adContextTextView.font = [UIFont fontWithName:@"Arial"size:14.0];//设置字体名字和字体大小
|
adContextTextView.delegate = self;//设置它的委托方法
|
adContextTextView.backgroundColor = [UIColor whiteColor];//设置它的背景颜色
|
adContextTextView.keyboardType = UIKeyboardTypeDefault;//键盘类型
|
adContextTextView.scrollEnabled = YES;//是否可以拖动
|
adContextTextView.placeholder = @"在这里输入广告内容";
|
adContextTextView.limitLength = [[NSNumber alloc] initWithInt:200]; // 限制字数
|
[ad_context_bk addSubview: adContextTextView];//加入到整个页面中
|
|
|
UIImageView * ad_scroll_type_bk = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20+148+20, SCREEN_WIDTH-20, 93)];
|
ad_scroll_type_bk.image = [UIImage imageNamed:@"ad_scroll_type_bk"];
|
ad_scroll_type_bk.userInteractionEnabled = YES;
|
[self.view addSubview:ad_scroll_type_bk];
|
|
UIImageView * ad_scroll_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 16, 16)];
|
ad_scroll_tag.image = [UIImage imageNamed:@"ad_scroll_tag"];
|
[ad_scroll_type_bk addSubview:ad_scroll_tag];
|
|
_adContextLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(30, 2,SCREEN_WIDTH-60, 30)];
|
_adContextLabel.font = [UIFont systemFontOfSize:14];
|
_adContextLabel.textAlignment = UITextAlignmentLeft;
|
_adContextLabel.textColor = kUIColorFromRGB(0x00b744);
|
_adContextLabel.text = @"设置广告滚动方式";
|
[ad_scroll_type_bk addSubview:_adContextLabel];
|
|
UIImageView * ad_context_line2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, ad_scroll_type_bk.frame.size.width-20, 1)];
|
ad_context_line2.image = [UIImage imageNamed:@"ad_context_line"];
|
[ad_scroll_type_bk addSubview:ad_context_line2];
|
|
CGFloat scrollW = ad_scroll_type_bk.frame.size.width/2-20;
|
|
updownScrolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
updownScrolBtn.frame = CGRectMake((ad_scroll_type_bk.frame.size.width/2 - scrollW)/2, 45, scrollW, 26);
|
|
[updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk1" ] forState:UIControlStateNormal];
|
[updownScrolBtn setTitle:@"上下滚动" forState:UIControlStateNormal];
|
updownScrolBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
|
[updownScrolBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
updownScrolBtn.layer.masksToBounds=YES;
|
updownScrolBtn.layer.cornerRadius=8.0f;
|
[updownScrolBtn addTarget:self action:@selector(updownAction) forControlEvents:UIControlEventTouchUpInside];
|
[ad_scroll_type_bk addSubview:updownScrolBtn];
|
|
rightleftScrolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
rightleftScrolBtn.frame = CGRectMake(ad_scroll_type_bk.frame.size.width/2+(ad_scroll_type_bk.frame.size.width/2 - scrollW)/2, 45, scrollW, 26);
|
|
[rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk2" ] forState:UIControlStateNormal];
|
[rightleftScrolBtn setTitle:@"左右滚动" forState:UIControlStateNormal];
|
rightleftScrolBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
|
[rightleftScrolBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
rightleftScrolBtn.layer.masksToBounds=YES;
|
rightleftScrolBtn.layer.cornerRadius=8.0f;
|
[rightleftScrolBtn addTarget:self action:@selector(rightleftAction) forControlEvents:UIControlEventTouchUpInside];
|
[ad_scroll_type_bk addSubview:rightleftScrolBtn];
|
|
|
UIImageView * ad_scroll_type_bk2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20+148+20+93+20, SCREEN_WIDTH-20, 93)];
|
ad_scroll_type_bk2.image = [UIImage imageNamed:@"ad_scroll_type_bk"];
|
ad_scroll_type_bk2.userInteractionEnabled = YES;
|
[self.view addSubview:ad_scroll_type_bk2];
|
|
UIImageView * ad_scroll_speed_tag = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 17, 17)];
|
ad_scroll_speed_tag.image = [UIImage imageNamed:@"ad_scroll_speed_tag"];
|
[ad_scroll_type_bk2 addSubview:ad_scroll_speed_tag];
|
|
GloriaLabel *_adContextLabel2 = [[GloriaLabel alloc] initWithFrame:CGRectMake(30, 2,SCREEN_WIDTH-60, 30)];
|
_adContextLabel2.font = [UIFont systemFontOfSize:14];
|
_adContextLabel2.textAlignment = UITextAlignmentLeft;
|
_adContextLabel2.textColor = kUIColorFromRGB(0x00b744);
|
_adContextLabel2.text = @"设置广告滚动速度";
|
[ad_scroll_type_bk2 addSubview:_adContextLabel2];
|
|
UIImageView * ad_context_line3 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, ad_scroll_type_bk2.frame.size.width-20, 1)];
|
ad_context_line3.image = [UIImage imageNamed:@"ad_context_line"];
|
[ad_scroll_type_bk2 addSubview:ad_context_line3];
|
|
_trackingSlider = [[ASValueTrackingSlider alloc]initWithFrame:CGRectMake(10, 70, ad_scroll_type_bk2.frame.size.width-20, 40)];
|
|
_trackingSlider.delegate = self;
|
_trackingSlider.dataSource = self;
|
_trackingSlider.popUpViewCornerRadius = 5.0;
|
[_trackingSlider setMaxFractionDigitsDisplayed:0];
|
_trackingSlider.popUpViewColor = kUIColorFromRGB(0x00b744);
|
_trackingSlider.font = [UIFont fontWithName:@"GillSans-Bold" size:12];
|
_trackingSlider.textColor = [UIColor whiteColor];
|
_trackingSlider.maximumValue = 100;
|
_trackingSlider.minimumValue = 0;
|
//_trackingSlider.formatStr = @"%@℃";
|
//[_trackingSlider setValue: [__wenDuStr intValue]];
|
[_trackingSlider showPopUpView];
|
[ad_scroll_type_bk2 addSubview:_trackingSlider];
|
|
|
UIButton * fabuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
fabuBtn.frame = CGRectMake((SCREEN_WIDTH-350)/2, 20+148+20+93+20+93+20, 350, 40);
|
|
[fabuBtn setBackgroundImage:[UIImage imageNamed:@"ad_fabu_btn_bk" ] forState:UIControlStateNormal];
|
[fabuBtn setTitle:@"发 布" forState:UIControlStateNormal];
|
fabuBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
|
[fabuBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
fabuBtn.layer.masksToBounds=YES;
|
fabuBtn.layer.cornerRadius=8.0f;
|
[fabuBtn addTarget:self action:@selector(fabuAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:fabuBtn];
|
|
[self get_device_ad];
|
// Do any additional setup after loading the view.
|
}
|
|
-(void)fabuAction
|
{
|
//[UserDefault stringForKey:@"user_id"]
|
NSString *path = [[NSString alloc] initWithFormat:UPDATE_AD];
|
|
//params.put("mac",mac);
|
//params.put("ad_content",ad_content);
|
//params.put("ad_rollmd",ad_rollmd+"");
|
//params.put("ad_speed",ad_speed+"");
|
//params.put("ad_mode",ad_mode+"");
|
|
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
|
|
[param setObject:_currentModel.mac forKey:@"mac"];
|
[param setObject:adContextTextView.text forKey:@"ad_content"];
|
[param setObject:[NSString stringWithFormat:@"%d",hotelSelModel.ad_rollmd] forKey:@"ad_rollmd"];
|
[param setObject:[NSString stringWithFormat:@"%d",hotelSelModel.ad_speed] forKey:@"ad_speed"];
|
[param setObject:[NSString stringWithFormat:@"%d",hotelSelModel.ad_mode] forKey:@"ad_mode"];
|
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody)
|
{
|
MPStrongSelf(self);
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
|
if(resModel.code == 0)
|
{
|
//发送成功提示
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
else
|
{
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}
|
failure:^(NSString *error)
|
{
|
|
[Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
}
|
|
-(void)get_device_ad
|
{
|
|
//[UserDefault stringForKey:@"user_id"]
|
NSString *path = [[NSString alloc] initWithFormat:@"%@",[NSString stringWithFormat:GET_DEVICE_AD,self.currentModel.mac]];
|
|
//params.put("mac",mac);
|
//params.put("ad_content",ad_content);
|
//params.put("ad_rollmd",ad_rollmd+"");
|
//params.put("ad_speed",ad_speed+"");
|
//params.put("ad_mode",ad_mode+"");
|
|
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
|
|
//param setObject:<#(nonnull id)#> forKey:<#(nonnull id<NSCopying>)#>
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody)
|
{
|
MPStrongSelf(self);
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
|
if(resModel.code == 0)
|
{
|
//发送成功提示
|
if(![Global isEmptyObject:resModel.content])
|
{
|
|
hotelSelModel = [AdModel mj_objectWithKeyValues:resModel.content];
|
|
adContextTextView.placeholderLabel.hidden = YES;
|
adContextTextView.text = hotelSelModel.ad_content;
|
//@property(nonatomic, strong) NSString * _id;//": "590abf002b153bee6e5b682b",
|
//@property(nonatomic, strong) NSString * ad_content;//": "广告内容-200字以内",
|
//@property(nonatomic, assign) int ad_rollmd;//": 1,
|
//@property(nonatomic, assign) int ad_speed;//": 50,
|
//@property(nonatomic, assign) int ad_mode;//": 1
|
//滚动方式 1左右,2上下
|
if(hotelSelModel.ad_rollmd == 1)
|
{
|
[rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk2" ] forState:UIControlStateNormal];
|
[updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk1" ] forState:UIControlStateNormal];
|
}
|
else if(hotelSelModel.ad_rollmd == 2)
|
{
|
[rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk1" ] forState:UIControlStateNormal];
|
[updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk2" ] forState:UIControlStateNormal];
|
}
|
|
[_trackingSlider setValue: hotelSelModel.ad_speed];
|
}
|
else
|
{
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}
|
else
|
{
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}
|
failure:^(NSString *error)
|
{
|
|
[Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
|
}
|
|
-(void)updownAction
|
{
|
//滚动方式 1左右,2上下
|
if(hotelSelModel.ad_rollmd == 1)
|
{
|
[rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk1" ] forState:UIControlStateNormal];
|
[updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk2" ] forState:UIControlStateNormal];
|
}
|
|
hotelSelModel.ad_rollmd = 2;
|
}
|
|
-(void)rightleftAction
|
{
|
//滚动方式 1左右,2上下
|
if(hotelSelModel.ad_rollmd == 2)
|
{
|
[rightleftScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_right_left_bk2" ] forState:UIControlStateNormal];
|
[updownScrolBtn setBackgroundImage:[UIImage imageNamed:@"ad_scroll_up_down_bk1" ] forState:UIControlStateNormal];
|
}
|
|
hotelSelModel.ad_rollmd = 1;
|
}
|
|
-(void)backAction
|
{
|
[self dismissViewControllerAnimated:YES completion:nil];
|
}
|
|
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
#pragma mark - ASValueTrackingSliderDelegate
|
- (NSString *)slider:(ASValueTrackingSlider *)slider stringForValue:(float)value
|
{
|
NSString * valueStr = [NSString stringWithFormat:@"%d",(int)value];
|
//self._wenDuStr = valueStr;
|
|
// LOG_INFO(@"当前选择数值:%@℃",self._wenDuStr);
|
|
hotelSelModel.ad_speed = (int)value;
|
|
return valueStr;
|
}
|
|
- (void)sliderWillDisplayPopUpView:(ASValueTrackingSlider *)slider{
|
|
}
|
|
- (void)sliderDidHidePopUpView:(ASValueTrackingSlider *)slider{
|
|
}
|
|
#pragma mark disappear keyboard begin
|
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
|
{
|
// 在编辑范围是否允许输入某些text
|
// 如果你的textView里面不允许用回车,可以用此方法通过按回车回收键盘
|
if ([text isEqualToString:@"\n"])
|
{
|
[textView resignFirstResponder];
|
return NO;
|
}
|
else
|
{
|
return YES;
|
}
|
}
|
|
|
- (void)textViewDidEndEditing:(UITextView *)textView
|
{
|
if ([textView isFirstResponder]) {
|
[textView resignFirstResponder];
|
}
|
}
|
|
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
{
|
[self textViewDidEndEditing:adContextTextView];
|
}
|
|
/*
|
#pragma mark - Navigation
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
// Get the new view controller using [segue destinationViewController].
|
// Pass the selected object to the new view controller.
|
}
|
*/
|
|
@end
|