一,效果图

二,代码。

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. Windows Phone开发手记-WinRT下自定义圆形ItemsControl

    这里的ItemsControl指的是Xaml里的集合控件,包括ListView,GridView等,此篇博客主要参考MSDN Blog的一篇文章,具体出处为:http://blogs.msdn.com ...

  2. POJ 2453

    #include <iostream> #include <algorithm> #include <cmath> #define MAXN 1000 #defin ...

  3. 11-01 Java 开发工具 eclipse从下载、安装到实际使用的详细教程

     Eclipse和MyEclipse简介 Eclipse是一种可扩展的开放源代码的IDE.起始于1999年4月,由OTI和IBM两家公司的IDE产品开发组组建. 2001年11月,IBM公司捐出价值4 ...

  4. vs 2017 IIS EXPRESS 增加局域网访问

    在VS调试站点,默认使用IISExpress,locall+端口,为了使用IP地址.多域名调试,找到 IISExpress下的applicationhost.config,在目标站点下增加类似行: & ...

  5. Java语言基础(方法与数组)_DAY05

    1:函数(掌握)   (1)定义在类中,有特定功能的一段小程序,可以独立运行.    (2)函数的格式:       修饰符 返回值类型 函数名(形参类型 形式参数1,形参类型 形式参数2...)   ...

  6. Python动态变量名定义与调用

    动态变量名赋值 在使用tkinter时需要动态生成变量,如动态生成var1...var10变量 使用exec动态赋值 exec在python3中是内置函数,它支持python代码的动态执行. 示例: ...

  7. Python多线程-Event(事件对象)

    Event 事件对象管理一个内部标志,通过set()方法将其设置为True,并使用clear()方法将其设置为False.wait()方法阻塞,直到标志为True.该标志初始为False. 方法: i ...

  8. Redis学习系列二之.Net开发环境搭建及基础数据结构String字符串

    一.简介 Redis有5种基本数据结构,分别是string.list(列表).hash(字典).set(集合).zset(有序集合),这是必须掌握的5种基本数据结构.注意Redis作为一个键值对缓存系 ...

  9. vim常用命令总结(转)

    vim常用命令 -------------------------------------------------------------------------------------------- ...

  10. 分析NonfairSync加锁/解锁过程

    类继承关系: NonfairSync => Sync => AbstractQueuedSynchronizer 类NonfairSync final void lock() { if ( ...