一,效果图

二,代码。

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. ss的使用配置(电脑、手机FQ)

    注:FQ仅用于google查阅资料等,禁止违规违法行为 自己搭建ss服务 1.vps购买:https://www.alpharacks.com/holiday 按流程填完相关信息(Operating ...

  2. 提取PPT中的原始图片

    写Word的不如做Excel 的,做Excel不如做PPT的,写代码的不如做PPT. 为了在电子邮件中上传PPT,其中的图片大都经过压缩,以便缩小PPT的体积.那么如何将PPT中的图片,还原成没有经过 ...

  3. WebDriver高级应用实例(2)

    2.1在日期选择器上进行日期选择 被测网页的网址: https://www.html5tricks.com/demo/Kalendae/index.html Java语言版本的API实例代码 impo ...

  4. [POC]K8 DLLhijack Test

    POC: 2016.11 Winrar却持 XP资源管理器却持 DLL却持VS全版本 https://www.cnblogs.com/k8gege/p/10261254.html POC:https: ...

  5. 用AOP思想改造一个服务器的数据存储

    背景是有一个游戏服务器一直以来都是写SQL的, 后来改过一段时间的redis, 用的是别的员工写的类orm方式将实体类型映射成各种key-value对进行写入, 但是仍有一个缺点就是需要在增\删\改的 ...

  6. Selenium自动化测试Python二:WebDriver基础

    WebDriver基础 欢迎阅读WebDriver基础讲义.本篇讲义将会重点介绍Selenium WebDriver的环境搭建和基本使用方法. WebDriver环境搭建 Selenium WebDr ...

  7. MyBatis中如何一次执行多条语句(使用mysql数据库)

    解决办法不外乎有三个:1.多条sql分批执行:2.存储过程或函数调用:3.sql批量执行. MyBatis中如何一次执行多条语句(使用mysql数据库): 1.修改数据库连接参数加上allowMult ...

  8. Redis随笔(五)Jedis、jedisCluster的使用

    1.Jedis客户端 https://redis.io/clients 2.Jedis源码包与使用介绍 https://github.com/xetorthio/jedis 3.项目中使用 通过mav ...

  9. list string 互转

    List转字符串,用逗号隔开 List<string> list = new List<string>();list.Add("a");list.Add(& ...

  10. Python学习--12 异常处理、调试

    异常捕获 语法格式: try: pass except xxx as e: pass except xxx as e: pass ... else: pass finally: pass except ...