//
// PersonalGenderButtonView.h
// OatosIphoneClient2.0
//
// Created by IPhone开发 on 14-7-3.
// Copyright (c) 2014年 qycloud. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface PersonalGenderButtonView : UIView
- (void)setBtnClickedBlock:(OatosBaseBlock)block;
@end
//
// PersonalGenderButtonView.m
// OatosIphoneClient2.0
//
// Created by IPhone开发 on 14-7-3.
// Copyright (c) 2014年 qycloud. All rights reserved.
//
#import "PersonalGenderButtonView.h"
#import "PadPopoverCotentView.h"
@interface PersonalGenderButtonView ()
{
OatosBaseBlock _clickBlock;
}
@property (nonatomic, strong) UIButton *maleButton;
@property (nonatomic, strong) UIButton *femaleButton;
// 性别选择回调
@property (nonatomic, strong) NSString *gender;
@end
@implementation PersonalGenderButtonView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self createButtonView];
}
return self;
}
- (void)createButtonView
{
self.maleButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.maleButton.frame = CGRectMake(0.0, 0.0, self.frame.size.width, 36.0);
self.maleButton.tag = 0;
[self.maleButton setTitle:@"男" forState:UIControlStateNormal];
[self.maleButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[self.maleButton setTitleColor:kPadTabBarCellTitleColor forState:UIControlStateNormal];
[self.maleButton addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.maleButton];
UIImage *img = [UIImage imageNamed:@"operation_line.png"];
UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0.0,39, self.frame.size.width, img.size.height)];
line.image = img;
[self addSubview:line];
line = nil;
self.femaleButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.femaleButton.frame = CGRectMake(0.0, 40.0, self.frame.size.width, 36.0);
[self.femaleButton setTitle:@"女" forState:UIControlStateNormal];
self.femaleButton.tag = 1;
[self.femaleButton setTitleColor:kPadTabBarCellTitleColor forState:UIControlStateNormal];
[self.femaleButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[self.femaleButton addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.femaleButton];
}
- (void)setBtnClickedBlock:(OatosBaseBlock)block
{
_clickBlock = block;
}
- (void)btnClicked:(id)sender
{
UIButton *btn = (id)sender;
if(btn.tag == 0)
{
_gender = @"m";
}
else
{
_gender = @"f";
}
if(_clickBlock)
{
_clickBlock (_gender);
}
}
@end
#pragma mark 设置性别
-(void)createClicked:(id) sender
{
if (_popView)
{
[_popView dismissAnimated:NO];
_popView = nil;
}
UIButton *btn = (UIButton *)sender;
PersonalGenderButtonView *genderView = [[PersonalGenderButtonView alloc] initWithFrame:CGRectMake(0, 0, 120, 80)];
PadPopoverCotentView *popTipView = [[PadPopoverCotentView alloc] initWithCustomView:genderView];
self.genderView = genderView;
popTipView.pointDirection = OatosPointDirectionDown;
_popView = popTipView;
[_popView presentAtPointTarget:btn inView:self.view animated:YES];
if (popTipView.overlayView) {
[popTipView.overlayView setTouchedBlock:^(id data) {
[_popView dismissAnimated:YES];
_popView = nil;
}];
}
__weak typeof(self) weakSelf = self;
[self.genderView setBtnClickedBlock:^(id data) {
typeof(self) strongSelf = weakSelf;
if (strongSelf != nil) {
[strongSelf updateGender:data];
}
}];
return;
}
- (void)updateGender:(NSString *)gender
{
[self.personalInfoModel.tableDataDic setObject:gender forKey:@"gender"];
if([gender isEqualToString:@"f"])
{
[self.btnGender setTitle:@"女" forState:UIControlStateNormal];
}
else
{
[self.btnGender setTitle:@"男" forState:UIControlStateNormal];
}
[_popView dismissAnimated:YES];
_popView = nil;
}