IOS - 会员中心页面和逻辑
2015-07-09 16:34
417 查看
会员中心界面:
根据VIP状态的不同, 显示不同内容, 并设置按钮跳转支付页面.
代码
会员中心页面
根据VIP状态的不同, 显示不同内容, 并设置按钮跳转支付页面.
代码
// // MemberCenterViewController.h // SymptomChecker // // Created by C.L.Wang on 15/7/9. // // /** * 会员中心页面, 根据VIP状态显示不同. * @{link AutoLoginManager#queryUsableService}设置VIP状态 */ #import "CYModelViewController.h" @interface MATMemberCenterViewController : CYModelViewController @end
// // MemberCenterViewController.m // SymptomChecker // // Created by C.L.Wang on 15/7/9. // // #import "MATMemberCenterViewController.h" #import "VIPAlipayViewController.h" // 支付页面 #import "UserLoginViewController.h" // 登录页面 #define kViewRatio viewWidth()/320 // 宽度单位 @interface MATMemberCenterViewController () @end @implementation MATMemberCenterViewController { UIImageView *_memberStateIcon; // 会员状态图片 UILabel *_memberStateText; // 会员状态文字 UILabel *_serviceOfOwnership; // 拥有服务 UILabel *_noserviceOfOwnership; // 未拥有服务 UIView *_infiniteTimesItem; // 健康数据 UIView *_selfExaminationItem; // 自我检查 UIView *_healthDataItem; // 无线次数 FilledColorButton *_processButton; // 处理按钮 BOOL _needRefresh; // 是否刷新 } // 初始化类 - (id) initWithNavigatorURL:(NSURL *)URL query:(NSDictionary *)query { self = [super initWithNavigatorURL:URL query:query]; if (self) { [self resetData]; } return self; } // 重置数据 - (void) resetData { _needRefresh = YES; } // 页面初始化 - (void)viewDidLoad { [super viewDidLoad]; self.title = @"会员中心"; } // 页面显示 - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear: animated]; if (_needRefresh && [User hasLoggedIn]) { _needRefresh = NO; NSMutableDictionary* access = [[NSMutableDictionary alloc] init]; if ([[User currentUser] matIsVip] == 1) { // VIP [access setObject:@"icon_mat_isvip" forKey:@"memberStateIcon"]; [access setObject:@"已开通会员包月服务" forKey:@"memberStateText"]; [access setObject:@1 forKey:@"noserviceOfOwnership"]; [access setObject:@"icon_mat_checked" forKey:@"infiniteTimesItem"]; [access setObject:@"立即续费" forKey:@"processButton"]; } else { // 非VIP [access setObject:@"icon_mat_notvip" forKey:@"memberStateIcon"]; [access setObject:@"暂未开通会员优惠" forKey:@"memberStateText"]; [access setObject:@0 forKey:@"noserviceOfOwnership"]; [access setObject:@"icon_mat_notcheck" forKey:@"infiniteTimesItem"]; [access setObject:@"立即开通" forKey:@"processButton"]; } [self createModelWithDict:access]; } } /** * 创建界面, VIP不同页面不同 * * @param access 是否VIP */ - (void) createModelWithDict:(NSMutableDictionary*)access { [self.view setBackgroundColor:[UIColor whiteColor]]; // 会员状态图标 _memberStateIcon = [CYResource loadImageView:access[@"memberStateIcon"] andFrame:CGRectMake(viewWidth()/2-36*kViewRatio, 36*kViewRatio, 72*kViewRatio, 72*kViewRatio)]; [self.view addSubview:_memberStateIcon]; // 会员状态文字 _memberStateText = [UILabel labelWithFrame:CGRectMake(0, _memberStateIcon.bottom+8*kViewRatio, viewWidth(), 36*kViewRatio) fontSize:20*kViewRatio fontColor:[UIColor blackColor] text:access[@"memberStateText"]]; [_memberStateText setAdjustsFontSizeToFitWidth:YES]; [_memberStateText setTextAlignment:NSTextAlignmentCenter]; [self.view addSubview:_memberStateText]; // 服务标题 _serviceOfOwnership = [UILabel labelWithFrame:CGRectMake(12*kViewRatio, _memberStateText.bottom, viewWidth(), 48*kViewRatio) fontSize:18*kViewRatio fontColor:[UIColor blackColor] text:@"已享有服务"]; [_serviceOfOwnership setAdjustsFontSizeToFitWidth:YES]; [_serviceOfOwnership setTextAlignment:NSTextAlignmentLeft]; [self.view addSubview:_serviceOfOwnership]; // 健康工具项 _healthDataItem = [[UIView alloc] initWithFrame:CGRectMake(12*kViewRatio, _serviceOfOwnership.bottom, viewWidth(), 32*kViewRatio)]; [self.view addSubview:[self viewOfCombinationWithView:_healthDataItem image:@"icon_mat_checked" text:@"健康数据跟踪记录"]]; // 自我检查项 _selfExaminationItem = [[UIView alloc] initWithFrame:CGRectMake(12*kViewRatio, _healthDataItem.bottom, viewWidth(), 32*kViewRatio)]; [self.view addSubview:[self viewOfCombinationWithView:_selfExaminationItem image:@"icon_mat_checked" text:@"自我检查全面分析"]]; // 未服务标题 CGRect cr = CGRectMake(12*kViewRatio, _selfExaminationItem.bottom, viewWidth(), ([access[@"noserviceOfOwnership"] intValue]==0)?48*kViewRatio:0); _noserviceOfOwnership = [UILabel labelWithFrame:cr fontSize:18*kViewRatio fontColor:[UIColor blackColor] text:([access[@"noserviceOfOwnership"] intValue]==0)?@"开通可享有服务":@""]; [_noserviceOfOwnership setAdjustsFontSizeToFitWidth:YES]; [_noserviceOfOwnership setTextAlignment:NSTextAlignmentLeft]; [self.view addSubview:_noserviceOfOwnership]; // 无线次数项 _infiniteTimesItem = [[UIView alloc] initWithFrame:CGRectMake(12*kViewRatio, _noserviceOfOwnership.bottom, viewWidth(), 32*kViewRatio)]; [self.view addSubview:[self viewOfCombinationWithView:_infiniteTimesItem image:access[@"infiniteTimesItem"] text:@"在线问诊不限次数"]]; // 处理按钮 _processButton = [[FilledColorButton alloc] initWithFrame:CGRectMake(12*kViewRatio, _infiniteTimesItem.bottom, viewWidth()-24*kViewRatio, 40*kViewRatio) type:kFilledBtnGreen title:access[@"processButton"]]; [_processButton addTarget: self action: @selector(onSubmitBtnPressedAfterLogin:) forControlEvents: UIControlEventTouchUpInside]; [self.view addSubview:_processButton]; } /** * 左图片和右文字组合控件 * * @param view 父控件 * @param imageName 图片本地路径 * @param text 文字 * * @return 组合控件 */ - (UIView*) viewOfCombinationWithView:(UIView*)view image:(NSString*)imageName text:(NSString*)text { // 图片视图 UIImageView* iv = [CYResource loadImageView:imageName andFrame:CGRectMake(0, 0, 16*kViewRatio, 16*kViewRatio)]; [iv setContentMode:UIViewContentModeScaleToFill]; // 文字视图 [view addSubview:iv]; UILabel* tv = [UILabel labelWithFrame:CGRectMake(32*kViewRatio, 0, viewWidth(), 16*kViewRatio) fontSize:16*kViewRatio fontColor:[UIColor grayColor] text:text]; [view addSubview:tv]; return view; } // 按钮点击事件 - (void) onSubmitBtnPressedAfterLogin:(UIButton*) sender { NIDPRINTMETHODNAME(); if (![User hasLoggedIn]) { _needRefresh = YES; UserLoginViewController *controller = [UserLoginViewController new]; [self cyPresentModalViewController:controller animated:YES]; } else { NSDictionary *fakeData = @{@"source": @"vip", @"problem_id": ENSURE_NOT_NULL(@"1234"), @"ignore_tel": @(YES)}; VIPAlipayViewController* controller = [[VIPAlipayViewController alloc]initWithNavigatorURL:nil query:fakeData]; [self.navigationController pushViewController:controller animated:YES]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
会员中心页面
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- iOS开发之路--微博OAuth授权_取得用户授权的accessToken
- ios通过按钮点击异步加载图片
- ios中图像进行压缩方法汇总
- IOS检测指定路径的文件是否存在
- iOS、Mac OS X系统中编程实现汉字转拼音的方法(超级简单)