【代码笔记】iOS-自定义选择框(高底强弱)
一,效果图

二,代码。
ViewController.h

#import <UIKit/UIKit.h> @interface ViewController : UIViewController
<UIPickerViewDataSource,UIPickerViewDelegate> @end

ViewController.m

#import "ViewController.h"
#define Color(r, g, b,d) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:d]
#define W [UIScreen mainScreen].bounds.size.width
#define H [UIScreen mainScreen].bounds.size.height @interface ViewController ()
{
NSMutableArray *arrayData;
UIView *chooseView;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. //初始化选择界面
[self addChooseView];
}
#pragma -mark -functions
//初始化选择页面
-(void)addChooseView
{
//背景框
chooseView = [[UIView alloc]initWithFrame:CGRectMake(0,H- H*0.45, W, H*0.45)];
chooseView.backgroundColor = Color(230, 230, 230, 1);
[self.view addSubview:chooseView]; //完成按钮上面的线
UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, W, 1)];
line3.backgroundColor = Color(202, 202, 202, 1);
[chooseView addSubview:line3]; //完成按钮下面的线
UIView *line4 = [[UIView alloc]initWithFrame:CGRectMake(0, 40, W, 1)];
line4.backgroundColor = Color(202, 202, 202, 1);
[chooseView addSubview:line4]; //完成按钮
UIButton *finishedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
finishedBtn.frame = CGRectMake(W-50, 5, 50, 30);
[finishedBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[finishedBtn setTitle:@"完成" forState:UIControlStateNormal];
[finishedBtn addTarget:self action:@selector(doClickFinishButton) forControlEvents:UIControlEventTouchUpInside];
[chooseView addSubview:finishedBtn]; UIPickerView *choosePicker = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, W, chooseView.bounds.size.height-40)];
choosePicker.delegate = self;
choosePicker.dataSource = self;
[chooseView addSubview:choosePicker]; arrayData=[[NSMutableArray alloc]initWithObjects:@"高",@"中",@"强",@"弱", nil]; }
#pragma -mark -doClickActions
-(void)doClickFinishButton
{
chooseView.hidden=YES;
NSLog(@"点击完成按钮");
}
#pragma -mark -UIPickerViewDelegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return arrayData.count;
} - (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [arrayData objectAtIndex:row];
} - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *chooseStr = [NSString stringWithFormat:@"%ld", (long)row];
NSLog(@"---chooseStr--%@",chooseStr);
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

【代码笔记】iOS-自定义选择框(高底强弱)的更多相关文章
- 帮助自定义选择框样式的Javascript - DropKick.js
来源:GBin1.com 在线演示 在线下载 当你想要设计一个页面样式时,没有什么比表单更让人头疼了.而当你设计一个表单的样式时,最让你头疼的就应该非下拉框<select>莫属了. 我们 ...
- JavaScript学习笔记之下拉选择框的操作
对于下拉框的操作十分繁多,这几天项目须要就总结一下 一.动态构建option 有时候我们须要动态构建下拉选择框里面的值,这里我们就要用到 var varItem = new Option(" ...
- iOS自定义拍照框拍照&裁剪(一)
卡片机时代 很重要的一点是,相机本身是没有方向概念的,它不理解拍摄的内容,只会以相机自己的坐标系去保存数据,下图展示了相机对"F"进行四个角度拍摄时返回的图片数据. 最初的卡片机时 ...
- 【代码笔记】iOS-先选择城市,然后,跳转Tabbar
一,效果图. 二,工程图. 三,代码. ChooseCityViewController.h #import <UIKit/UIKit.h> @interface ChooseCityVi ...
- 【代码笔记】Web-ionic单选框
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- 左右选择框 js插件
随着项目的进展,测试工程师在更多的浏览器中兼容性测试中,发现有些浏览器不支持option的触发事件,这就造成了先前一篇博文bootstrap 左右框多项选择示例 中左右选择框的失效,于是我就由原先的s ...
- 【代码笔记】iOS-时间选择框
一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...
- 【代码笔记】iOS-点击出现选择框
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【代码笔记】iOS-单项选择框
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
随机推荐
- 反向读取Mysql数据库表结构到PowerDesigner中
使用PowerDesigner挺长时间了,只是一些简单的表结构设计,因需要对当前数据库进行再设计,需要看一下数据库中所有的表,及表之间的关系,并重新修改表结构,因此需求就是怎么把数据库中的表结构反向生 ...
- 阿里云RDS数据库备份文件恢复到本地数据库
参考这里:https://help.aliyun.com/knowledge_detail/41817.html 第4.2步要多注释掉一些(应该根据实际报错来注释): [mysqld] innodb_ ...
- Flask 微博三方登录
1.进入微博开发平台(https://open.weibo.com/),注册账号,填写开发者信息 2.创建应用.创建应用完成后,可以在"我的应用 - 应用信息"中查看您所创建应用的 ...
- vue教程1-09 交互 vue实现百度下拉列表
vue教程1-09 交互 vue实现百度下拉列表 <!DOCTYPE html> <html lang="en"> <head> <met ...
- odoo开发笔记 -- 前台不同视图访问同一个模型
看一下partner这个表, 客户和供应商,都用这个表,那怎么区分呢: 供应商: 客户 注意这两个里面用domain来进行区分: <field name="domain" ...
- Celery -- 分布式任务队列 及实例
Celery 使用场景及实例 Celery介绍和基本使用 在项目中如何使用celery 启用多个workers Celery 定时任务 与django结合 通过django配置celery perio ...
- ilspy反编译
资料: http://www.cnblogs.com/JamesLi2015/archive/2011/09/08/2170519.html 软件: http://ilspy.net/
- IDEA中Git的使用基础
场景概述 工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 ...
- solr(四) : springboot 整合 solr
前言: solr服务器搭起来, 数据导入之后, 就该应用到项目中去了. 那在项目中, 该怎么整合和应用solr呢? 接下来, 就来整合和应用solr 一. 整合 1. 引入jar包 <prope ...
- Maven 入门——Maven 的安装和配置
1.安装 Windows 环境 Maven 官网下载安装文件 解压到指定目录 配置环境变量(M2_HOME) cmd 输入 mvn -v Mac环境 brew install maven 配置环境变量 ...