当前位置: 首页 > news >正文

【代码笔记】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
复制代码

转载于:https://www.cnblogs.com/yang-guang-girl/p/7209484.html

相关文章:

  • 惨痛教训
  • python(二十八)
  • 页面查找技巧
  • SqlServer索引的原理与应用
  • Spring+SpringMVC+mybatis整合以及注解的使用(三)
  • vs2010 javascript代码折叠扩展插件
  • css定位
  • 最简单的手工写增,删,改,查的代码
  • Lucene 4.0 TieredMergePolicy
  • 关于表单修改
  • Ubuntu安装源配置文件/etc/apt/sources.list第X行有错误
  • 原型和原型链
  • Linux(ubuntu)下如何安装与卸载软件总结
  • 前端调试的一点新理解
  • Linux(ubuntu)下搭建Java开发环境 - 安装JDK
  • 【每日笔记】【Go学习笔记】2019-01-10 codis proxy处理流程
  • ABAP的include关键字,Java的import, C的include和C4C ABSL 的import比较
  • github从入门到放弃(1)
  • gops —— Go 程序诊断分析工具
  • GraphQL学习过程应该是这样的
  • iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码...
  • JavaScript 是如何工作的:WebRTC 和对等网络的机制!
  • Java多线程(4):使用线程池执行定时任务
  • Java反射-动态类加载和重新加载
  • java中的hashCode
  • Nodejs和JavaWeb协助开发
  • Python语法速览与机器学习开发环境搭建
  • React的组件模式
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • V4L2视频输入框架概述
  • 聊聊flink的TableFactory
  • 要让cordova项目适配iphoneX + ios11.4,总共要几步?三步
  • ​Python 3 新特性:类型注解
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • #stm32整理(一)flash读写
  • $.ajax()方法详解
  • (13)[Xamarin.Android] 不同分辨率下的图片使用概论
  • (2020)Java后端开发----(面试题和笔试题)
  • (3)STL算法之搜索
  • (Matalb回归预测)PSO-BP粒子群算法优化BP神经网络的多维回归预测
  • (Redis使用系列) Springboot 使用redis实现接口幂等性拦截 十一
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (十八)devops持续集成开发——使用docker安装部署jenkins流水线服务
  • (一)appium-desktop定位元素原理
  • *2 echo、printf、mkdir命令的应用
  • .net framework4与其client profile版本的区别
  • .NET 反射 Reflect
  • [ C++ ] STL---stack与queue
  • [20171101]rman to destination.txt
  • [AIGC] Redis基础命令集详细介绍
  • [android] 看博客学习hashCode()和equals()
  • [bzoj4010][HNOI2015]菜肴制作_贪心_拓扑排序
  • [C#] 基于 yield 语句的迭代器逻辑懒执行
  • [ERROR] Plugin 'InnoDB' init function returned error
  • [IE技巧] 如何让IE 启动的时候不加载任何插件