一,效果图

二,代码。

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-自定义选择框(高底强弱)的更多相关文章

  1. 帮助自定义选择框样式的Javascript - DropKick.js

    来源:GBin1.com 在线演示  在线下载 当你想要设计一个页面样式时,没有什么比表单更让人头疼了.而当你设计一个表单的样式时,最让你头疼的就应该非下拉框<select>莫属了. 我们 ...

  2. JavaScript学习笔记之下拉选择框的操作

    对于下拉框的操作十分繁多,这几天项目须要就总结一下 一.动态构建option 有时候我们须要动态构建下拉选择框里面的值,这里我们就要用到 var varItem = new Option(" ...

  3. iOS自定义拍照框拍照&裁剪(一)

    卡片机时代 很重要的一点是,相机本身是没有方向概念的,它不理解拍摄的内容,只会以相机自己的坐标系去保存数据,下图展示了相机对"F"进行四个角度拍摄时返回的图片数据. 最初的卡片机时 ...

  4. 【代码笔记】iOS-先选择城市,然后,跳转Tabbar

    一,效果图. 二,工程图. 三,代码. ChooseCityViewController.h #import <UIKit/UIKit.h> @interface ChooseCityVi ...

  5. 【代码笔记】Web-ionic单选框

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  6. 左右选择框 js插件

    随着项目的进展,测试工程师在更多的浏览器中兼容性测试中,发现有些浏览器不支持option的触发事件,这就造成了先前一篇博文bootstrap 左右框多项选择示例 中左右选择框的失效,于是我就由原先的s ...

  7. 【代码笔记】iOS-时间选择框

    一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...

  8. 【代码笔记】iOS-点击出现选择框

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  9. 【代码笔记】iOS-单项选择框

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

随机推荐

  1. flaks___git

    今天呢  我给大家分享一个超实用的一个把代码分享到云端的一种操作 比如我们在家里,要想做项目的话可以直接从云端上拉取下来代码直接开始工作了 而且还可以随时修改,没有地点的局限性了,只要你想敲,随时随地 ...

  2. 安卓APP简单后端的搭建

    写在前面: 此教程没有用到后端框架.只是单纯用servlet做一个例子,如果是学框架可以不用往下看了 本文适合哪些人:懂java的,会写android单机程序,懂得用HTTPClient等发送请求解析 ...

  3. Win7上Spark WordCount运行过程及异常

    WordCount.Scala代码如下: package com.husor.Spark /** * Created by huxiu on 2014/11/26. */ import org.apa ...

  4. hexo 静态页面生成后页面打不开的问题

    我这里的原因是4000端口被占用了 *** hexo入门指南教程: 官方文档 用Hexo 3 搭建github blog 做一款hexo主题(进阶) 坑 1 要安装node和git 2 别忘了安装he ...

  5. filebeat-1-连通logstash

    类似flume, 但功能更为强大 Filebeat是一个日志文件托运工具,在你的服务器上安装客户端后,filebeat会监控日志目录或者指定的日志文件,追踪读取这些文件(追踪文件的变化,不停的读),并 ...

  6. Maven 打包遇到的问题

    [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a ...

  7. tomcat关闭后线程依然运行解决办法

    tomcat关闭后线程依然运行解决办法,设置线程为守护线程 守护线程与非守护线程 最近在看多线程的Timer章节,发现运用到了守护线程,感觉Java的基础知识还是需要补充. Java分为两种线程:用户 ...

  8. Unity生成WebService代理类

    普通的.net程序中,如果我们想引用webService,只需在项目中右键选择添加服务引用,然后在地址栏中输入Webservice地址,单击“转到”按钮,找到服务后再单击确定,Visual Studi ...

  9. Conditional特性用法

    说明:根据预处理标识符执行方法.Conditional 特性是 ConditionalAttribute 的别名,可应用于方法或属性类.相对于#if和#endif,更灵活更简洁和不易出错. 例如: # ...

  10. Rectangles(第七届ACM省赛原题+最长上升子序列)

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100)  rec ...