|
//
// agreementController.m
// ThePaperBase
//
// Created by Huixin on 15/8/20.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "agreementController.h"
@interface agreementController () {
CGFloat contentHeight;
}
@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)UIView *titleLine;
@property(nonatomic, strong)RTLabel *contentLabel;
@property(nonatomic, strong)TPCustomButton *closeBtn;
@end
@implementation agreementController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.titleStr = @"注册";
[self.view addSubview:self.backScrollView];
[self.backScrollView addSubview:self.contentTitleLabel];
[self.backScrollView addSubview:self.titleLine];
[self.backScrollView addSubview:self.updateTimeLabel];
[self.backScrollView addSubview:self.contentLabel];
[self.backScrollView addSubview:self.closeBtn];
[self layoutViews]; //bug5389: 【适配性】【倒退】注册:注册协议显示不全
}
- (void)layoutViews {
[self.backScrollView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(self.barHeight, 0, 0, 0));
}];
[self.contentTitleLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backScrollView.top).offset(50);
make.left.equalTo(self.backScrollView.left);
make.right.equalTo(self.view.right);
make.height.mas_equalTo(@21);
}];
[self.titleLine makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentTitleLabel.bottom).offset(15);
make.left.equalTo(self.backScrollView.left).offset(24);
make.right.equalTo(self.view.right).offset(-24);
make.height.mas_equalTo(@1);
}];
[self.updateTimeLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLine.bottom).offset(15);
make.left.equalTo(self.backScrollView.left);
make.right.equalTo(self.view.right);
make.height.mas_equalTo(@14);
}];
[self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.updateTimeLabel.bottom).offset(53);
make.left.equalTo(self.backScrollView.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@1);
}];
[self.closeBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentLabel.bottom).offset(28);
make.left.equalTo(self.backScrollView.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@40);
}];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self remoteMethod];
}
#pragma mark - get method
- (UIScrollView*)backScrollView {
if (!_backScrollView) {
_backScrollView = [[UIScrollView alloc] init];
_backScrollView.backgroundColor = [UIColor clearColor];
_backScrollView.alwaysBounceVertical = YES;
_backScrollView.directionalLockEnabled = YES;
_backScrollView.scrollEnabled = YES;
}
return _backScrollView;
}
- (UILabel*)contentTitleLabel {
if (!_contentTitleLabel) {
_contentTitleLabel = [[UILabel alloc] init];
_contentTitleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_contentTitleLabel.font = appFont(TEXT_ONE_PLUS_LEVELSIZE, YES);
_contentTitleLabel.textAlignment = NSTextAlignmentCenter;
}
return _contentTitleLabel;
}
- (UIView*)titleLine {
if (!_titleLine) {
_titleLine = [[UIView alloc] init];
_titleLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
_titleLine.hidden = YES; //bug5291: 注册,进入注册协议loading时,应该是空白loading
}
return _titleLine;
}
- (UILabel*)updateTimeLabel {
if (!_updateTimeLabel) {
_updateTimeLabel = [[UILabel alloc] init];
_updateTimeLabel.textColor = [UIColor colorWithHexString:TextGray];
_updateTimeLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_updateTimeLabel.textAlignment = NSTextAlignmentCenter;
}
return _updateTimeLabel;
}
- (RTLabel*)contentLabel {
if (!_contentLabel) {
_contentLabel = [[RTLabel alloc] init];
_contentLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_contentLabel.lineSpacing = 8;
_contentLabel.textColor = [UIColor colorWithHexString:TextBlack];
_contentLabel.lineBreakMode = RTTextLineBreakModeWordWrapping;
_contentLabel.textAlignment = kCTLeftTextAlignment;
}
return _contentLabel;
}
- (TPCustomButton*)closeBtn {
if (!_closeBtn) {
_closeBtn = [TPCustomButton new];
_closeBtn.title = @"关闭";
[_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside];
_closeBtn.hidden = YES; //bug5291: 注册,进入注册协议loading时,应该是空白loading
}
return _closeBtn;
}
#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:@"。"];
}
}];
contentHeight = returnTextHeightWithRTLabel(Self.content, Self.contentLabel.frame.size.width, appFont(TEXT_FIVE_LEVELSIZE, NO), Self.contentLabel.lineSpacing);
[Self.backScrollView setContentSize:CGSizeMake(Self.view.frame.size.width, contentHeight+267)];
Self.titleLine.hidden = NO;
Self.closeBtn.hidden = NO;
Self.contentTitleLabel.text = Self.titleText;
Self.updateTimeLabel.text = Self.updateTime;
Self.contentLabel.text = Self.content;
[Self.contentLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(Self.updateTimeLabel.bottom).offset(53);
make.left.equalTo(Self.backScrollView.left).offset(20);
make.right.equalTo(Self.view.right).offset(-20);
make.height.mas_equalTo(contentHeight);
}];
}else {
}
}];
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[self.navigationController popViewControllerAnimated:YES];
}
- (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
|