你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS - 會員中心頁面和邏輯

IOS - 會員中心頁面和邏輯

編輯:IOS開發綜合

會員中心界面:
根據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

會員中心頁面
會員中心


 

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved