|
//
// agreementController.m
// ThePaperHD
//
// Created by scar1900 on 15/3/24.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "agreementController.h"
#import "MLNavigationController.h"
#import "KGModal.h"
@interface agreementController () {
}
@property(nonatomic, strong)UIButton *closeBtn;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)NSString *titleText;
@property(nonatomic, strong)NSString *updateTime;
@property(nonatomic, strong)NSString *content;
@property(nonatomic, strong)UIScrollView *backScrollView;
@property(nonatomic, strong)UILabel *contentTitleLabel;
@property(nonatomic, strong)UILabel *updateTimeLabel;
@property(nonatomic, strong)RTLabel *contentLabel;
@property(nonatomic, assign)CGFloat contentHeight;
@end
@implementation agreementController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor clearColor];
self.view.frame = CGRectMake(0, 0, loginPopUpSize.width, loginPopUpSize.height);
[self.view addSubview:self.closeBtn];
[self.view addSubview:self.titleLabel];
self.closeBtn.frame = CGRectMake(0, 0, 50, 80);
[self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
self.titleLabel.frame = CGRectMake(0,
0,
CGRectGetWidth(self.view.bounds),
80);
[self.view addSubview:self.backScrollView];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self remoteMethod];
}
- (UIScrollView*)backScrollView {
if (!_backScrollView) {
_backScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 80, loginPopUpSize.width, loginPopUpSize.height-80)];
_backScrollView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
_backScrollView.alwaysBounceVertical = YES;
_backScrollView.directionalLockEnabled = YES;
}
return _backScrollView;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
[KGModal sharedInstance].tapOutsideToDismiss = NO;
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
}
- (UIButton*)closeBtn {
if (!_closeBtn) {
_closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeBtn setImage:Image(@"login/popUpBack.png") forState:UIControlStateNormal];
[_closeBtn setImage:Image(@"login/popUpBack_h.png") forState:UIControlStateHighlighted];
[_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.text = @"用户协议";
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = appFont(30, NO);
}
return _titleLabel;
}
- (UILabel*)contentTitleLabel {
if (!_contentTitleLabel) {
_contentTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 45, loginPopUpSize.width, 25)];
_contentTitleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_contentTitleLabel.font = appFont(20, NO);
_contentTitleLabel.textAlignment = NSTextAlignmentCenter;
}
return _contentTitleLabel;
}
- (UILabel*)updateTimeLabel {
if (!_updateTimeLabel) {
_updateTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.contentTitleLabel.frame)+30, loginPopUpSize.width, 15)];
_updateTimeLabel.textColor = [UIColor colorWithHexString:TextGray];
_updateTimeLabel.font = appFont(14, NO);
_updateTimeLabel.textAlignment = NSTextAlignmentCenter;
}
return _updateTimeLabel;
}
- (RTLabel*)contentLabel {
if (!_contentLabel) {
_contentLabel = [[RTLabel alloc]initWithFrame:CGRectMake(25, 330/2, 860/2, self.contentHeight)];
_contentLabel.font = appFont(13, NO);
_contentLabel.lineSpacing = 8;
_contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_contentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
_contentLabel.textAlignment = kCTLeftTextAlignment;
}
return _contentLabel;
}
#pragma mark - remote method
- (void)remoteMethod {
__weak typeof(self) Self = self;
[Remote doNoneJsonActionWithBlock:0 requestUrl:agreementURL parameter:nil withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
NSString *responseString = responseData;
NSArray *list = [responseString componentsSeparatedByRegex:@","];
[list enumerateObjectsUsingBlock:^(NSString* obj, NSUInteger idx, BOOL *stop) {
if ([obj isMatchedByRegex:@"title"]) {
NSArray *strList = [obj componentsSeparatedByRegex:@"\":"];
Self.titleText = strList[1];
Self.titleText = [Self.titleText stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
Self.titleText = [Self.titleText stringByReplacingCharactersInRange:NSMakeRange(Self.titleText.length-1, 1) withString:@""];
}else if ([obj isMatchedByRegex:@"updateTime"]) {
NSArray *strList = [obj componentsSeparatedByRegex:@"\":"];
Self.updateTime = strList[1];
Self.updateTime = [Self.updateTime stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
Self.updateTime = [Self.updateTime stringByReplacingCharactersInRange:NSMakeRange(Self.updateTime.length-1, 1) withString:@""];
}else if ([obj isMatchedByRegex:@"content"]) {
NSArray *strList = [obj componentsSeparatedByRegex:@"\":"];
Self.content = strList[1];
Self.content = [Self.content stringByReplacingCharactersInRange:NSMakeRange(0, 2) withString:@""];
Self.content = [Self.content stringByReplacingOccurrencesOfString:@"}" withString:@""];
Self.content = [Self.content stringByReplacingOccurrencesOfString:@"。\"" withString:@"。"];
}
}];
CGFloat height = 330/2;
Self.contentHeight = returnTextHeightWithRTLabel(self.content, 860/2, appFont(13, NO), 8)+15;
[Self.backScrollView setContentSize:CGSizeMake(loginPopUpSize.width, height+Self.contentHeight)];
[Self.backScrollView addSubview:Self.contentTitleLabel];
Self.contentTitleLabel.text = Self.titleText;
[Self.backScrollView addSubview:Self.updateTimeLabel];
Self.updateTimeLabel.text = Self.updateTime;
[Self.backScrollView addSubview:Self.contentLabel];
Self.contentLabel.text = Self.content;
UIView* line = [[UIView alloc]initWithFrame:CGRectMake(loginPopUpSize.width/2-560/4,
CGRectGetMaxY(Self.contentTitleLabel.frame)+11,
560/2,
1)];
line.backgroundColor =[UIColor colorWithHexString:LINECOLOR];
[Self.backScrollView addSubview:line];
}else {
}
}];
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[(MLNavigationController*)self.navigationController popViewControllerWithPush];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
|