第二次使用回调

//
//  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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值