澎湃iPad上线版本

userInfoSexCell.m 5.7KB

    // // userInfoSexCell.m // ThePaperDemo // // Created by scar1900 on 14/12/11. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "userInfoSexCell.h" @interface userInfoSexCell() @property(nonatomic,strong)UIButton *maleButton; @property(nonatomic,strong)UIButton *femaleButton; @end @implementation userInfoSexCell @synthesize sex = _sex; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.pushIcon.hidden = YES; self.contentView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.maleButton]; [self.contentView addSubview:self.femaleButton]; } return self; } - (UIButton*)maleButton { if (!_maleButton) { _maleButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_maleButton setTitle:@"男" forState:UIControlStateNormal]; [_maleButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal]; [_maleButton setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateSelected]; [_maleButton setImage:Image(@"login/personSex.png") forState:UIControlStateNormal]; [_maleButton setImage:Image(@"login/personSex_s.png") forState:UIControlStateSelected]; _maleButton.titleLabel.textAlignment = NSTextAlignmentLeft; _maleButton.selected = NO; [_maleButton addTarget:self action:@selector(selectMale:) forControlEvents:UIControlEventTouchUpInside]; } _maleButton.titleLabel.font = appFont(15, NO); return _maleButton; } - (UIButton*)femaleButton { if (!_femaleButton) { _femaleButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_femaleButton setTitle:@"女" forState:UIControlStateNormal]; [_femaleButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal]; [_femaleButton setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateSelected]; [_femaleButton setImage:Image(@"login/personSex.png") forState:UIControlStateNormal]; [_femaleButton setImage:Image(@"login/personSex_s.png") forState:UIControlStateSelected]; _femaleButton.titleLabel.textAlignment = NSTextAlignmentLeft; _femaleButton.selected = NO; [_femaleButton addTarget:self action:@selector(selectFemale:) forControlEvents:UIControlEventTouchUpInside]; } _femaleButton.titleLabel.font = appFont(15, NO); return _femaleButton; } - (void)selectMale:(UIButton*)btn { if (btn.selected) { return; } NSDictionary *dic = @{@"sex":@"0"}; __block UIButton *button = self.femaleButton; [Remote doJsonActionWithBlock:0 requestUrl:editUserInfoURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]); NSString *lastLoginType = [TPUserDefault instance].userBO.loginType; user.loginType = lastLoginType; [TPUserDefault instance].userBO = user; ShowMessage(@"修改成功", YES); btn.selected = !btn.selected; if (btn.selected) { button.selected = NO; } }else { ShowTextMessage(message); } }]; } - (void)setSex:(NSString *)sexStr { _sex = sexStr; if ([sexStr intValue] == 0) { self.maleButton.selected = YES; self.femaleButton.selected = NO; }else { self.maleButton.selected = NO; self.femaleButton.selected = YES; } } - (void)selectFemale:(UIButton*)btn { if (btn.selected) { return; } NSDictionary *dic = @{@"sex":@"1"}; __block UIButton *button = self.maleButton; [Remote doJsonActionWithBlock:0 requestUrl:editUserInfoURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { userBO *user = setJsonDicToDataModel(responseData[@"userInfo"], [userBO class]); NSString *lastLoginType = [TPUserDefault instance].userBO.loginType; user.loginType = lastLoginType; [TPUserDefault instance].userBO = user; ShowMessage(@"修改成功", YES); btn.selected = !btn.selected; if (btn.selected) { button.selected = NO; } }else { ShowTextMessage(message); } }]; } - (void)layoutSubviews { [super layoutSubviews]; self.maleButton.frame = CGRectMake(120, 0, 40, CGRectGetHeight(self.bounds)); [self.maleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 25)]; [self.maleButton setImageEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(self.maleButton.bounds)/2-10, CGRectGetWidth(self.maleButton.bounds)-20, CGRectGetHeight(self.maleButton.bounds)/2-10, 0)]; self.femaleButton.frame = CGRectMake(CGRectGetMaxX(self.maleButton.frame)+35, 0, 40, CGRectGetHeight(self.bounds)); [self.femaleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 25)]; [self.femaleButton setImageEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(self.femaleButton.bounds)/2-10, CGRectGetWidth(self.femaleButton.bounds)-20, CGRectGetHeight(self.femaleButton.bounds)/2-10, 0)]; } - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end