• 【ios开发】自定义Actionsheet实现时间选择器和省市区选择器


    最近的工程有一个个人资料页面,需要填写生日和地区的信息,需要自己定义个actionsheet。

    但是到网上搜了一下都不太合适,只好自己研究研究,重写了一个。共享出来给大家用用,突然发现自己精神很高尚吗、,哈哈,其实是方便自己以后遇到类似的工程直接引用就好了。

    先上效果图:

    结构图:

    这里简单介绍一下Actionsheet类

    .h

    //
    //  CustomActionSheet.h
    //  test
    //
    //  Created by wxian on 13-12-2.
    //  Copyright (c) 2013年 wxian. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface CustomActionSheet : UIActionSheet <UIActionSheetDelegate>
    {
    
        NSString* customTitle;
    }
    
    -(id)initWithHeight:(float)height WithSheetTitle:(NSString*)title;
    @property (nonatomic, retain) UIView *customView;
    
    @end

    .m

    //
    //  CustomActionSheet.m
    //  test
    //
    //  Created by wxian on 13-12-2.
    //  Copyright (c) 2013年 wxian. All rights reserved.
    //
    
    #import "CustomActionSheet.h"
    
    #define NavBarHeight                    40
    #define ViewHeight                      459
    
    @interface CustomActionSheet(){
    @private
        float customViewHeight;
    }
    
    @end
    
    @implementation CustomActionSheet
    
    -(id)initWithHeight:(float)height WithSheetTitle:(NSString *)title
    {
        self = [super init];
        if (self) {
            customViewHeight = height;
            customTitle = title;
            self.customView = [[UIView alloc] initWithFrame:CGRectMake(0, ViewHeight - customViewHeight, 320, customViewHeight)];
        }
        return self;
    }
    
    //重写layoutSubviews
    -(void)layoutSubviews
    {
        [super layoutSubviews];
        UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, ViewHeight - customViewHeight -NavBarHeight, 320, NavBarHeight)];
        navBar.barStyle = UIBarStyleDefault;
        UINavigationItem *navItem = [[UINavigationItem alloc]initWithTitle:customTitle];
        UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleBordered target:self action:@selector(docancel)];
        navItem.leftBarButtonItem = leftButton;
        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleBordered target:self action:@selector(done)];
        navItem.rightBarButtonItem = rightButton;
        NSArray *array = [[NSArray alloc ]initWithObjects: navItem, nil];
        [navBar setItems:array];
        [self.superview addSubview:navBar];
        [self.superview addSubview:self.customView];
    
    }
    
    - (void) done{
        [self dismissWithClickedButtonIndex:0 animated:YES];
        [self.delegate actionSheet:self clickedButtonAtIndex:0];
    }
    
    - (void) docancel{
        [self dismissWithClickedButtonIndex:1 animated:YES];
        [self.delegate actionSheet:self clickedButtonAtIndex:1];
    }
    
    @end

    猛戳下载原代码

  • 相关阅读:
    jQuery实现radio第一次点击选中第二次点击取消功能(转)
    好用的文件下载类
    Windows获取远程Linux局域网内的mysql连接
    linux通过端口号查找程序执行路径
    linux几个命令
    java判断是移动端还是pc端
    jsp传给java属性,java生成json串,方便以后取出来
    如何在线程中获取spring 管理的bean
    [DeploymentService:290066]Error occurred while downloading files from admin server for deployment request "0". Underlying error is: "null"
    double,失去精度
  • 原文地址:https://www.cnblogs.com/ymonke/p/3454672.html
Copyright © 2020-2023  润新知