1 Star 0 Fork 11

Mist/MayStall-ios

forked from KevinHM/MayStall-ios 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ProductIDViewController.m 31.91 KB
一键复制 编辑 原始数据 按行查看 历史
Dawei Fan 提交于 2014-03-11 18:46 . submmit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
//
// ProductIDViewController.m
// Maystall
//
// Created by Liqun on 01/03/2014.
// Copyright (c) 2014 huiztech. All rights reserved.
//
#import "ProductIDViewController.h"
#import "AddCartViewController.h"
#import "CheckString.h"
#import "MayColorValue.h"
#import "MayValue.h"
#import "Config.h"
#import "CutImage.h"
#import "UIImageView+WebCache.h"
#import "SBJson.h"
#import "ASIFormDataRequest.h"
#import <QuartzCore/QuartzCore.h>
#import "CheckNetwork.h"
@interface ProductIDViewController ()
@end
@implementation ProductIDViewController
@synthesize ID_Product=ID_Product;
@synthesize Name_Product=Name_Product;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
webView_Information=[[UIWebView alloc]init];
array_shape=[[NSArray alloc]init];
size_array=[[NSMutableArray alloc]init];
color_array=[[NSMutableArray alloc]init];
label_buy_Num=[[UILabel alloc]init];
count_label=[[UILabel alloc]init];
totoal_BackGround=[[UIImageView alloc]init];
string_Numbers=@"0";
string_Money_total=@"0.00";
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, VIEW_HEIGHT)];
scrollView.contentSize=CGSizeMake(0, 570);
scrollView.delegate=self;
scrollView.backgroundColor=[UIColor clearColor];
[self.view addSubview:scrollView];
[self createNavigationBarItem];
[self getMainArray];
[self cartView_board];//cart select board
}
-(void)viewWillAppear:(BOOL)animated
{
self.tabBarController.navigationController.navigationBarHidden = NO;
self.navigationItem.title =@"Product Detail";
self. navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];//更改导航栏标题颜色 为白色
}
-(void)getMainArray
{
BOOL isNetWork=[CheckNetwork isExistenceNetwork];
[Config Instance].isNetworkRunning = [CheckNetwork isExistenceNetwork];
if(!isNetWork)//无网络
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"提示"
message:@"网络不佳,请重新操作试试看~"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles: @"确定",nil];
[alert show];
}
else
{
//http://www.maystall.com/index.php?route=mobile/ajax&action=product&product_id=283&debug=1
NSString *string=[NSString stringWithFormat:@"%@",kBASEURL];
NSURL *url = [ NSURL URLWithString : string ];
__weak ASIFormDataRequest *request = [ ASIFormDataRequest requestWithURL :url];
[request setRequestMethod:@"POST"];
[request setPostValue:kPRODCUT forKey:kACTION];
[request setPostValue:ID_Product forKey:kPRODUCT_ID];//ID_Product@"36"
//NSLog(@"%d",[request responseStatusCode]);
[request setCompletionBlock :^{
NSString * response = [request responseString];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *dict = [parser objectWithString:response];
[self creatTheProductDetail:dict];
}];
[request setFailedBlock :^{
}];
[request startAsynchronous ];//异步
}
}
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
// Create a graphics image context
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
-(void)creatTheProductDetail:(NSDictionary *)dict
{
NSLog(@"%@",dict);
array_shape=[dict objectForKey:@"options"];
UIImageView *image_Product=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 320)];
NSString *url=[NSString stringWithFormat:@"%@image/%@",webImageURL,[dict objectForKey:@"image"]] ;
[image_Product setImageWithURL:[NSURL URLWithString: url]
placeholderImage:[UIImage imageNamed:@"moren.png"]
success:^(UIImage *image) {
NSLog(@"产品详细图片显示成功OK ");
CGRect rect=[CutImage scaleImage:image toSize:CGRectMake(0.0, 0.0,300,320)];
image_Product.frame=CGRectMake((320-rect.size.width)/2, 0, rect.size.width,rect.size.height);
return ;
}
failure:^(NSError *error) {NSLog(@"产品详细图片显示失败NO");}];
[scrollView addSubview:image_Product];
UIImageView *imageView_NamePrice=[[UIImageView alloc]initWithFrame:CGRectMake(0, image_Product.frame.size.height, 320, 44)];
imageView_NamePrice.backgroundColor=[UIColor yellowColor];
scrollView.contentSize=CGSizeMake(0, image_Product.frame.size.height*2);
[scrollView addSubview:imageView_NamePrice];
UILabel *label_Name=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 240, 44)];
label_Name.backgroundColor=[UIColor orangeColor];
label_Name.font=[UIFont fontWithName:@"Helvetica" size:13.0];
if([CheckString isBlankString:[dict objectForKey:@"name"] ])
{
label_Name.text=@"null";
}
else
label_Name.text=[dict objectForKey:@"name"];
label_Name.textColor=TAB_COLOR_LIGHT;
label_Name.textAlignment=NSTextAlignmentCenter;
[imageView_NamePrice addSubview:label_Name];
UILabel *label_Price=[[UILabel alloc]initWithFrame:CGRectMake(240, 0,80 , 44)];
label_Price.backgroundColor=[UIColor clearColor];
label_Price.textColor=TAB_COLOR_LIGHT;
label_Price.textAlignment=NSTextAlignmentCenter;
NSString *stringMoney=[NSString stringWithFormat:@"%@",[dict objectForKey:@"special"]];
BOOL isString=[CheckString isBlankString:[dict objectForKey:@"special"]];
if(isString)//为空 显示price
{
if([CheckString isBlankString:[dict objectForKey:@"price"]])
label_Price.text=@"0";
else
label_Price.text=[dict objectForKey:@"price"];
}
else//special 不为空 显示 special
{
label_Price.text=stringMoney;
}
string_Money_Single=label_Price.text;
[imageView_NamePrice addSubview:label_Price];
float height=image_Product.frame.size.height+44;
height_ever=height;
[self createSecondaryTab:height];//创建下方选择 评价 产品规格选项按钮
NSString *html;
if([CheckString isBlankString:[dict objectForKey:@"intro"]])
html=@"null";
else
html=[dict objectForKey:@"intro"];
html=[self htmlEntityDecode :html];
NSString *bodyHTML = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<link href=\"default.css\" rel=\"stylesheet\" type=\"text/css\" /> \n"
"</head> \n"
"<body\">%@</body> \n"
"</html>", html];
[webView_Information loadHTMLString:bodyHTML baseURL:[NSURL URLWithString:@"http://www.maystall.com/"]];
webView_Information.delegate=self;
[self createBottomBar];
}
-(NSString *)htmlEntityDecode:(NSString *)string
{
string = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];
string = [string stringByReplacingOccurrencesOfString:@"&apos;" withString:@"'"];
string = [string stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];
string = [string stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
string = [string stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
return string;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)createSecondaryTab:(float)height//Home页面 最新 最好 的两个选择按钮
{
UIView *secondaryTabView = [[UIView alloc] initWithFrame:CGRectMake(0, height, 320, 33)];
secondaryTabView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_btn_wave"]];
CGSize titleSize = [@"Introduction" sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
_newestBtn = [[UIButton alloc] init];
_newestBtn.titleLabel.Font = [UIFont fontWithName:@"Helvetica" size:12.0];
_newestBtn.frame = CGRectMake(40, 6, titleSize.width += 10, 21);
_newestBtn.tag=100;
[_newestBtn setBackgroundImage:[UIImage imageNamed:@"btn_wave_selected"] forState:UIControlStateSelected];
[_newestBtn setTitleColor:TAB_COLOR_DARK forState:UIControlStateNormal];
[_newestBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[_newestBtn setTitle:@"Graphic" forState:UIControlStateNormal];
[_newestBtn addTarget:self action:@selector(BtnSelected:) forControlEvents:UIControlEventTouchUpInside];
_newestBtn.selected = YES;
_bestSellerBtn = [[UIButton alloc] init];
int marginRight = 320-40-titleSize.width-10;
_bestSellerBtn.tag=200;
_bestSellerBtn.titleLabel.Font = [UIFont fontWithName:@"Helvetica" size:12.0];
_bestSellerBtn.frame = CGRectMake(marginRight, 6, titleSize.width += 10, 21);
[_bestSellerBtn setBackgroundImage:[UIImage imageNamed:@"btn_wave_selected"] forState:UIControlStateSelected];
[_bestSellerBtn setTitleColor:TAB_COLOR_DARK forState:UIControlStateNormal];
[_bestSellerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[_bestSellerBtn setTitle:@"Introduction" forState:UIControlStateNormal];
[_bestSellerBtn addTarget:self action:@selector(BtnSelected:) forControlEvents:UIControlEventTouchUpInside];
[secondaryTabView addSubview:_newestBtn];
[secondaryTabView addSubview:_bestSellerBtn];
[scrollView addSubview:secondaryTabView];
}
- (void)createNavigationBarItem
{
//左键
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 60, 31);
[leftButton setTitle:@"Back" forState:UIControlStateNormal];
[leftButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
[leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(backToPreviousView) forControlEvents:UIControlEventTouchUpInside];
[leftButton setBackgroundImage:[UIImage imageNamed:@"btn_nav_back"] forState:UIControlStateNormal];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] init];
[leftItem setCustomView:leftButton];
self.navigationItem.leftBarButtonItem = leftItem;
//右键
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 40, 31);
[rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(backToPreviousView) forControlEvents:UIControlEventTouchUpInside];
[rightButton setBackgroundImage:[UIImage imageNamed:@"btn_nav_home"] forState:UIControlStateNormal];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] init];
[rightItem setCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)createBottomBar
{
int height = [UIScreen mainScreen].bounds.size.height - [UIApplication sharedApplication].statusBarFrame.size.height -44 -49;
bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, height, 320, 49)];
// bottomView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
bottomView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_bottom_tab"]];
/*
//评论按钮
commentBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 49)];
[commentBtn setTitle:@"commen" forState:UIControlStateNormal];
[commentBtn setTitleColor:TAB_COLOR_LIGHT forState:UIControlStateNormal];
[commentBtn setImage:[UIImage imageNamed:@"icon_product_comment"] forState:UIControlStateNormal ];
// [commentBtn setImage:[UIImage imageNamed:@"icon_product_comment"] forState:UIControlStateHighlighted];
[commentBtn setTitleEdgeInsets:UIEdgeInsetsMake(30.0, -22.0, 5.0, 0.0)];
[commentBtn setImageEdgeInsets:UIEdgeInsetsMake(-10, 20, 0, 0)];
[commentBtn addTarget:self action:@selector(commentBtnSelected) forControlEvents:UIControlEventTouchUpInside];
commentBtn.backgroundColor = [UIColor clearColor];
commentBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
[bottomView addSubview:commentBtn];
*/
//收藏按钮
favoriteBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 49)];
[favoriteBtn setTitle:@"favorite" forState:UIControlStateNormal];
[favoriteBtn setTitleColor:TAB_COLOR_LIGHT forState:UIControlStateNormal];
[favoriteBtn setImage:[UIImage imageNamed:@"icon_product_favorite_normal"] forState:UIControlStateNormal ];
// [favoriteBtn setImage:[UIImage imageNamed:@"icon_product_favorite_normal"] forState:UIControlStateHighlighted];
[favoriteBtn setImage:[UIImage imageNamed:@"icon_product_favorite_selected"] forState:UIControlStateSelected];
[favoriteBtn setTitleEdgeInsets:UIEdgeInsetsMake(30.0, -22.0, 5.0, 0.0)];
[favoriteBtn addTarget:self action:@selector(favoriteBtnSelected) forControlEvents:UIControlEventTouchUpInside];
[favoriteBtn setImageEdgeInsets:UIEdgeInsetsMake(-10, 20, 0, 0)];
favoriteBtn.backgroundColor = [UIColor clearColor];
favoriteBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
[bottomView addSubview:favoriteBtn];
//分享按钮
shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(83.3, 0, 70, 49)];
[shareBtn setTitle:@"share" forState:UIControlStateNormal];
[shareBtn setTitleColor:TAB_COLOR_LIGHT forState:UIControlStateNormal];
[shareBtn setImage:[UIImage imageNamed:@"icon_product_share"] forState:UIControlStateNormal];
// [shareBtn setImage:[UIImage imageNamed:@"icon_product_share"] forState:UIControlStateHighlighted];
[shareBtn setTitleEdgeInsets:UIEdgeInsetsMake(30.0, -22.0, 5.0, 0.0)];
[shareBtn setImageEdgeInsets:UIEdgeInsetsMake(-10, 20, 0, 0)];
[shareBtn addTarget:self action:@selector(shareBtnSelected) forControlEvents:UIControlEventTouchUpInside];
shareBtn.backgroundColor = [UIColor clearColor];
shareBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
[bottomView addSubview:shareBtn];
//购物车按钮 //249.9 166.6
cartBtn = [[UIButton alloc] initWithFrame:CGRectMake(249.9, 0, 70, 49)];
[cartBtn setTitle:@"cart" forState:UIControlStateNormal];
[cartBtn setTitleColor:TAB_COLOR_LIGHT forState:UIControlStateNormal];
[cartBtn setImage:[UIImage imageNamed:@"icon_product_cart"] forState:UIControlStateNormal];
// [cartBtn setImage:[UIImage imageNamed:@"icon_product_cart"] forState:UIControlStateHighlighted];
[cartBtn setTitleEdgeInsets:UIEdgeInsetsMake(30.0, -22.0, 5.0, 0.0)];
[cartBtn setImageEdgeInsets:UIEdgeInsetsMake(-10, 20, 0, 0)];
[cartBtn addTarget:self action:@selector(cartBtnSelected) forControlEvents:UIControlEventTouchUpInside];
cartBtn.backgroundColor = [UIColor clearColor];
cartBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
[bottomView addSubview:cartBtn];
[self.view addSubview:bottomView];
}
-(void)cartView_board
{
//cart View
view_Select=[[UIView alloc] init] ;
view_Select.frame=CGRectMake(0,View_Bottom_Height-49-44-20, 320, 0);
view_Select.backgroundColor=[UIColor yellowColor];
}
#pragma -mark webView Delegate
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// NSString *height_str= [webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"];
// document.documentElement.innerText;//获取网页内容文字
webView.frame = CGRectMake(10,height_ever+5+33,300,100);
// [scrollView addSubview:webView_Information];
CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
//CGFloat width = [[webView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
CGRect frame = webView.frame;
frame.size.height = height;
frame.size.width = 300;
webView.frame = frame;
/*
NSString *stringText= [webView stringByEvaluatingJavaScriptFromString: @"document.documentElement.innerText"];
// Rounded corners.
label_text=[[UILabel alloc]init];
label_text.text=stringText;
label_text.backgroundColor=[UIColor whiteColor];
label_text.frame=CGRectMake(15,height_ever+5+33,300,150);
//自动折行设置
label_text.textAlignment=NSTextAlignmentLeft;//左顶格
label_text.lineBreakMode = NSLineBreakByWordWrapping;
label_text.numberOfLines = 0;
[label_text sizeToFit];//高度自动适应
//
// Rounded corners.
label_text.layer.cornerRadius =5;
// A thin border.
label_text.layer.borderColor = TAB_COLOR_LIGHT.CGColor;
label_text.layer.borderWidth = 0.3;
// Drop shadow.
label_text.layer.shadowColor = [UIColor blackColor].CGColor;
label_text.layer.shadowOpacity = 1.0;
label_text.layer.shadowRadius = 7.0;
label_text.layer.shadowOffset = CGSizeMake(0, 4);
[scrollView addSubview:label_text];
*/
}
#pragma -mark button action
-(void)BtnSelected:(id)sender
{
UIButton *btn=(UIButton *)sender;
NSLog(@"%d",btn.tag);
if(btn.tag==100)//左
{
_newestBtn.selected = YES;
_bestSellerBtn.selected = NO;
//[scrollView addSubview:webView_Information];
[webView_Information removeFromSuperview];
[label_text removeFromSuperview];
}
else
{
_newestBtn.selected = NO;
_bestSellerBtn.selected = YES;
[scrollView addSubview:webView_Information];
}
}
- (void)backToPreviousView
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)commentBtnSelected
{
// CommentViewController *view = [[CommentViewController alloc] init];
// [self.navigationController pushViewController:view animated:YES];
}
- (void)favoriteBtnSelected
{
if (isFavorited) {
isFavorited = NO;
favoriteBtn.selected = NO;
}else{
isFavorited = YES;
favoriteBtn.selected = YES;
}
}
- (void)shareBtnSelected
{
}
- (void)cartBtnSelected
{
if (isCarted) {
isCarted = NO;
cartBtn.selected = NO;
// [UIView animateWithDuration:0.3f animations:^{
// view_Select.frame=CGRectMake(0,View_Bottom_Height-49-44-20, 320, 0);
// } completion:^(BOOL finished) {
//
// [view_Select removeFromSuperview];
// }];
}else{
isCarted = YES;
cartBtn.selected = YES;
//NSLog(@"%@",array_shape);
//取消按钮start
UIButton *button = [[UIButton alloc] init];
button.titleLabel.Font = [UIFont fontWithName:@"Helvetica" size:12.0];
button.frame = CGRectMake(258, 10,60, 30);
UIImageView *view_buttonBack=[[UIImageView alloc]initWithFrame:button.frame];
view_buttonBack.image=[UIImage imageNamed:@"search_box_bottom.png"];
UIImageView *btn_select=[[UIImageView alloc]initWithFrame:button.frame];
btn_select.image=[UIImage imageNamed:@"btn_add_cart_normal.png"];
UILabel *label_button=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
label_button.text=@"Cancel";
label_button.textAlignment=NSTextAlignmentCenter;
label_button.font=[UIFont fontWithName:@"Helvetica" size:12.0];
[button addSubview:label_button];
[button setImage:view_buttonBack.image forState:UIControlStateNormal];
[button addTarget:self action:@selector(Cancel_theSelcetBoard) forControlEvents:UIControlEventTouchUpInside];
[view_Select addSubview:button];
//取消按钮end
int height=0;
if(array_shape.count==0)
{
height=100;
}
else
{
[size_array removeAllObjects];
[color_array removeAllObjects];
for(int j=0;j<array_shape.count ;j++)
{
UILabel *label_column_first=[[UILabel alloc]initWithFrame:CGRectMake(10, 8+j*50, 50, 15)];
label_column_first.text=[[array_shape objectAtIndex:j]objectForKey:@"name"];
label_column_first.Font = [UIFont fontWithName:@"Helvetica" size:13.0];
[view_Select addSubview:label_column_first];
NSDictionary *dict=[array_shape objectAtIndex:j];
NSArray *array_column=[[NSArray alloc]init];
array_column=[dict objectForKey:@"option_value"];
NSMutableArray *contain=[[NSMutableArray alloc]init];
for (int i=0;i<array_column.count;i++) {
NSDictionary *dict_child=[array_column objectAtIndex:i];
UIButton *button = [[UIButton alloc] init];
button.titleLabel.Font = [UIFont fontWithName:@"Helvetica" size:12.0];
button.frame = CGRectMake(10+70*i, 25+j*50,60, 30);
height=MAX(height,25+j*50+30);
UIImageView *view_buttonBack=[[UIImageView alloc]initWithFrame:button.frame];
view_buttonBack.image=[UIImage imageNamed:@"search_box_bottom.png"];
UIImageView *btn_select=[[UIImageView alloc]initWithFrame:button.frame];
btn_select.image=[UIImage imageNamed:@"btn_add_cart_normal.png"];
UILabel *label_button=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
label_button.text=[dict_child objectForKey:@"name"];
label_button.textAlignment=NSTextAlignmentCenter;
label_button.font=[UIFont fontWithName:@"Helvetica" size:12.0];
[button addSubview:label_button];
button.tag=[[dict_child objectForKey:@"option_value_id"]integerValue];
[button setImage:view_buttonBack.image forState:UIControlStateNormal];
if(j==0)
[button addTarget:self action:@selector(Btn_Size_Sender:) forControlEvents:UIControlEventTouchUpInside];
if(j==1)
[button addTarget:self action:@selector(Btn_Color_Sender:) forControlEvents:UIControlEventTouchUpInside];
// button.selected = NO;
[contain addObject:button];
[view_Select addSubview:button];
}
if(j==0)
[size_array addObject:contain];
if(j==1)
[color_array addObject:contain];
}
UILabel *number_label=[[UILabel alloc]init];
number_label.frame=CGRectMake(10, height+5, 100, 15);
number_label.text=@"Number";
number_label.Font = [UIFont fontWithName:@"Helvetica" size:13.0];
[view_Select addSubview:number_label];
UIImageView *number_left=[[UIImageView alloc]init];
number_left.frame=CGRectMake(10, height+30, 40, 35);
number_left.image=[UIImage imageNamed:@"buy_btn_left.png"];
UIButton *subtract=[[UIButton alloc]initWithFrame:number_left.frame];
[subtract setImage: number_left.image forState:UIControlStateNormal];
[subtract addTarget:self action:@selector(Decrease) forControlEvents:UIControlEventTouchUpInside];
[view_Select addSubview:subtract];
UIImageView *number_right=[[UIImageView alloc]init];
number_right.frame=CGRectMake(110, height+30, 40, 35);
UIButton *add=[[UIButton alloc]initWithFrame:number_right.frame];
number_right.image=[UIImage imageNamed:@"buy_btn_right.png"];
[add setImage: number_right.image forState:UIControlStateNormal];
[add addTarget:self action:@selector(Increase) forControlEvents:UIControlEventTouchUpInside];
[view_Select addSubview:add];
[self.view addSubview:view_Select];
label_buy_Num.text=string_Numbers;
label_buy_Num.textAlignment=NSTextAlignmentCenter;
label_buy_Num.Font = [UIFont fontWithName:@"Helvetica" size:14.0];
label_buy_Num.backgroundColor=[UIColor whiteColor];
label_buy_Num.frame=CGRectMake(50, height+30, 60, 33);
[view_Select addSubview:label_buy_Num];
}
[UIView animateWithDuration:0.3f animations:^{
view_Select.frame=CGRectMake(0,View_Bottom_Height-44-20-200-49, 320, 200+49);
} completion:^(BOOL finished) {
[bottomView removeFromSuperview];
}];
totoal_BackGround.frame=CGRectMake(0,view_Select.frame.size.height-49,320,49);
totoal_BackGround.backgroundColor=[UIColor whiteColor];
[view_Select addSubview:totoal_BackGround];
UILabel *totalLabel_Word=[[UILabel alloc]initWithFrame:CGRectMake(2, 5, 80, 40)];
totalLabel_Word.backgroundColor=[UIColor redColor];
totalLabel_Word.text=@"Total (RM):";
totalLabel_Word.textAlignment=NSTextAlignmentCenter;
totalLabel_Word.Font = [UIFont fontWithName:@"Helvetica" size:14.0];
[totoal_BackGround addSubview:totalLabel_Word];
count_label.frame=CGRectMake(85, 5,130 , 40);
count_label.backgroundColor=[UIColor grayColor];
count_label.textColor=TAB_COLOR_DARK ;
count_label.textAlignment=NSTextAlignmentCenter;
count_label.Font = [UIFont fontWithName:@"Helvetica" size:17.0];
count_label.text=string_Money_total;
[totoal_BackGround addSubview:count_label];
totoal_BackGround.userInteractionEnabled=YES;//当前视图可点选
UIButton *btn_pay=[UIButton buttonWithType:UIButtonTypeCustom];
btn_pay.frame=CGRectMake(220,5, 90, 40);
UIImageView *view_btnPay=[[UIImageView alloc]initWithFrame:btn_pay.frame];
view_btnPay.image=[UIImage imageNamed:@"btn_add_cart_normal.png"];
[btn_pay setImage:view_btnPay.image forState:UIControlStateNormal];
[btn_pay addTarget:self action:@selector(ToPay) forControlEvents:UIControlEventTouchUpInside];
[totoal_BackGround addSubview:btn_pay];
UILabel *label_toPay=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 90, 40)];
label_toPay.text=@"To Pay";
label_toPay.textAlignment=NSTextAlignmentCenter;
label_toPay.textColor=[UIColor whiteColor];
label_toPay.backgroundColor=[UIColor clearColor];
[btn_pay addSubview:label_toPay];
}
}
-(void)Btn_Size_Sender:(id)sender
{
UIButton *btn=(UIButton *)sender;
NSLog(@"%d",btn.tag);
UIImageView *view_buttonBack=[[UIImageView alloc]initWithFrame:btn.frame];
view_buttonBack.image=[UIImage imageNamed:@"search_box_bottom.png"];
UIImageView *btn_select=[[UIImageView alloc]initWithFrame:btn.frame];
btn_select.image=[UIImage imageNamed:@"btn_add_cart_normal.png"];
[btn setImage:btn_select.image forState:UIControlStateNormal];
for(int i=0;i<size_array.count;i++)
{
NSArray *array_btn=[[NSArray alloc]init];
array_btn=[size_array objectAtIndex:i];
for(int j=0;j<array_btn.count;j++)
{
UIButton *btn_Other=(UIButton *) [array_btn objectAtIndex:j];
if(btn_Other.tag==btn.tag)
{
isSize=YES;
}
else
{
[btn_Other setImage:view_buttonBack.image forState:UIControlStateNormal];
}
}
}
}
-(void)Btn_Color_Sender:(id)sender
{
UIButton *btn=(UIButton *)sender;
NSLog(@"%d",btn.tag);
UIImageView *view_buttonBack=[[UIImageView alloc]initWithFrame:btn.frame];
view_buttonBack.image=[UIImage imageNamed:@"search_box_bottom.png"];
UIImageView *btn_select=[[UIImageView alloc]initWithFrame:btn.frame];
btn_select.image=[UIImage imageNamed:@"btn_add_cart_normal.png"];
[btn setImage:btn_select.image forState:UIControlStateNormal];
for(int i=0;i<color_array.count;i++)
{
NSArray *array_btn=[[NSArray alloc]init];
array_btn=[color_array objectAtIndex:i];
for(int j=0;j<array_btn.count;j++)
{
UIButton *btn_Other=(UIButton *) [array_btn objectAtIndex:j];
if(btn_Other.tag==btn.tag)
{
isColor=YES;
}
else
{
[btn_Other setImage:view_buttonBack.image forState:UIControlStateNormal];
}
}
}
}
-(void)Cancel_theSelcetBoard
{
[UIView animateWithDuration:0.3f animations:^{
view_Select.frame=CGRectMake(0,View_Bottom_Height-49-44-20, 320, 0);
} completion:^(BOOL finished) {
[view_Select removeFromSuperview];
[self.view addSubview:bottomView];
}];
}
-(void)Decrease
{
int num=[string_Numbers integerValue];
num--;
if(num<=0)
{
num=0;
}
string_Numbers=[NSString stringWithFormat:@"%d",num];
label_buy_Num.text=string_Numbers;
float single_money=[string_Money_Single floatValue];
float total_money=[string_Money_Single floatValue];
total_money=single_money*num;
string_Money_total=[NSString stringWithFormat:@"%.2f",total_money];
count_label.text=string_Money_total;
[totoal_BackGround addSubview:count_label];
[view_Select addSubview:label_buy_Num];
}
-(void)Increase
{
int num=[string_Numbers integerValue];
num++;
string_Numbers=[NSString stringWithFormat:@"%d",num];
label_buy_Num.text=string_Numbers;
float single_money=[string_Money_Single floatValue];
float total_money=[string_Money_Single floatValue];
total_money=single_money*num;
string_Money_total=[NSString stringWithFormat:@"%.2f",total_money];
count_label.text=string_Money_total;
[totoal_BackGround addSubview:count_label];
[view_Select addSubview:label_buy_Num];
}
-(void)ToPay
{
if(!isSize||!isColor)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mention"
message:@"The Size or Color could not be empty! "
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
return;
}
else if([string_Numbers isEqualToString:@"0"])
{
UIAlertView *alert_Two = [[UIAlertView alloc] initWithTitle:@"Mention"
message:@"The Number could not be Zero!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert_Two show];
return;
}
UIAlertView *alert_Third = [[UIAlertView alloc] initWithTitle:@"Darling"
message:@"Your goods have been added the shopping cart~ Do you want to pay now?"
delegate:self
cancelButtonTitle:@"NO"
otherButtonTitles:@"YES", nil];
[alert_Third show];
}
- (void)browserMore
{
}
//delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0)//NO
{
}
if(buttonIndex==1)//YES
{
AddCartViewController * AddCartVC = [[AddCartViewController alloc] initWithNibName:@"AddCartViewController" bundle:nil];
[self.navigationController pushViewController :AddCartVC animated:YES];
}
NSLog(@"%d",buttonIndex);
}
@end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mist/MayStall-ios.git
git@gitee.com:mist/MayStall-ios.git
mist
MayStall-ios
MayStall-ios
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385