今天要介绍一下更多的控键使用, 当然也会对上一篇说的控件做一个巩固, 所以这一篇涉及到的控键会包括 UIImage、UITextField、UIButton、UILabel、UISwitch、以及 UIActionSheetDelegate的使用。

BIDViewController.h

#import <UIKit/UIKit.h>

@interface BIDViewController : UIViewController <UIActionSheetDelegate>    //     声明使用到UIActionSheetDelegate
@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *numberField;
@property (weak, nonatomic) IBOutlet UILabel *sliderLabel;
@property (weak, nonatomic) IBOutlet UISwitch *leftSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *rightSwitch;
@property (weak, nonatomic) IBOutlet UIButton *doSomethingButton; - (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroundTap:(id)sender;
- (IBAction)sliderChanged:(UISlider *)sender;
- (IBAction)switchChanged:(UISwitch *)sender;
- (IBAction)toggleControls:(UISegmentedControl *)sender;
- (IBAction)buttonPressed:(id)sender; @end

BIDViewController.m

#import "BIDViewController.h"

@interface BIDViewController ()

@end

@implementation BIDViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.sliderLabel.text = @""; // 为UILabel缚值
UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"]; // 根据图片的名字获取UIImage对象
UIEdgeInsets insets = UIEdgeInsetsMake(, , , ); // 定义一个参数分别是上左下右的矩行框
UIImage *stretchableButtonImageNormal = [buttonImageNormal
resizableImageWithCapInsets:insets]; // 定义图片的拉伸区域, 有点儿像 .9图片哦
[self.doSomethingButton setBackgroundImage:stretchableButtonImageNormal
forState:UIControlStateNormal]; // 设置按钮的背景图 UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];
UIImage *stretchableButtonImagePressed = [buttonImagePressed
resizableImageWithCapInsets:insets];
[self.doSomethingButton setBackgroundImage:stretchableButtonImagePressed
forState:UIControlStateHighlighted]; // 设置按钮的背景图, 不同的是这个背景图在按钮触发的显示
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder]; // 放弃第一响应者, 让键盘隐藏
} - (IBAction)backgroundTap:(id)sender {
[self.nameField resignFirstResponder]; // 放弃第一响应者, 让键盘隐藏
[self.numberField resignFirstResponder];
} - (IBAction)sliderChanged:(UISlider *)sender {
int progress = lroundf(sender.value); // 获取slider的值并且进行四舍五入的折算
self.sliderLabel.text = [NSString stringWithFormat:@"%d", progress]; // 傅值label
} - (IBAction)switchChanged:(UISwitch *)sender {
BOOL setting = sender.isOn; // 获取当前switch的值
[self.leftSwitch setOn:setting animated:YES]; 为switch设值
[self.rightSwitch setOn:setting animated:YES];
} - (IBAction)toggleControls:(UISegmentedControl *)sender {
// 0 == switches index
if (sender.selectedSegmentIndex == ) {
self.leftSwitch.hidden = NO; // 隐藏
self.rightSwitch.hidden = NO; // 隐藏
self.doSomethingButton.hidden = YES; // 显示
}
else {
self.leftSwitch.hidden = YES;
self.rightSwitch.hidden = YES;
self.doSomethingButton.hidden = NO;
}
} - (IBAction)buttonPressed:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No Way!"
destructiveButtonTitle:@"Yes, I’m Sure!"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
// UIActionSheet是在iOS弹出的选择按钮项
} // UIActionSheet 消失的时候调用
- (void)actionSheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
// UIActionSheet 消失不是由于点击cancelButton触发
if (buttonIndex != [actionSheet cancelButtonIndex])
{
NSString *msg = nil; if (self.nameField.text.length > )
msg = [NSString stringWithFormat:
@"You can breathe easy, %@, everything went OK.",
self.nameField.text];
else
msg = @"You can breathe easy, everything went OK."; // 创建UIAlertView对象
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Something was done"
message:msg
delegate:self
cancelButtonTitle:@"Phew!"
otherButtonTitles:nil];
[alert show];
}
}
@end

ios成长之每日一遍(day 3)的更多相关文章

  1. ios成长之每日一遍(day 8)

    这几天都有一些任务要跟, 把ios的学习拉后, 看看要抓紧咯, 看看轮到的学习的是UITableView. BIDAppDelegate.h #import <UIKit/UIKit.h> ...

  2. ios成长之每日一遍(day 5)

    iOS 屏幕方向那点事儿http://zhenby.com/blog/2013/08/20/talk-ios-orientation/ 针对当前的屏幕方向进行对应的代码布局 BIDViewContro ...

  3. ios成长之每日一遍(day 1)

    Hello world开始. 这里不讨论如何创建项目导入项目.由于趁上班时间打酱油所以也不谈细节, 只谈具体项目的实现与关键流程的解析, 只供本人实际程况使用.不喜请移驾. 首先来谈谈 AppDele ...

  4. ios成长之每日一遍(day 7)

    今天到UITabBarController 结合 UIPickView, 这里一共有5个实现, 由浅到易. 其实在IB上面使用UITabBarController很简单, 就像平常拖控件一样拖到界面上 ...

  5. ios成长之每日一遍(day 6)

    toolBar上的View Switcher BIDAppDelegate.h #import <UIKit/UIKit.h> @class BIDSwitchViewController ...

  6. ios成长之每日一遍(day 4)

    今天, 主要讲四种常见的问题, 废话不多说了, 直接开始. 自动布局:这个我发现有一篇文章写得非常好, 直接表明出地http://www.cocoachina.com/applenews/devnew ...

  7. ios成长之每日一遍(day 2)

    接着下来简单说说Label(相当于android的textview)和button的使用, 由于都是与上篇的AppDelegate一致, 所以这一篇就说说ViewController与xib的使用呗. ...

  8. iOS:从头捋一遍VC的生命周期

    一.介绍 UIViewController是iOS开发中的核心控件,没有它那基本上任何功能都无法实现,虽然系统已经做了所有控件的生命维护,但是,了解它的生命周期是如何管理还是非常有必要的.网上有很多教 ...

  9. IOS成长之路-用NSXMLParser实现XML解析

    再次对xml进行解析,又有了些理解,如果有不对的地方,请给小弟指出,谢谢! <?xml version="1.0" encoding="UTF-8"?&g ...

随机推荐

  1. [BZOJ2616]SPOJ PERIODNI 树形dp+组合数+逆元

    2616: SPOJ PERIODNI Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 128  Solved: 48[Submit][Status][ ...

  2. [USACO08FEB]修路Making the Grade

    [USACO08FEB]修路Making the Grade比较难的dp,比赛时打的找LIS,然后其他的尽可能靠近,40分.先举个例子61 2 3 1 4 561 2 3 3 4 5第4个1要么改成3 ...

  3. WIN10下使用Anaconda配置opencv、tensorflow、pygame并在pycharm中运用

    昨天想运行一段机器学习的代码,在win10系统下配置了一天的python环境,真的是头疼,准备写篇博客来帮助后面需要配置环境的兄弟. 1.下载Anaconda 根据昨天的经历,发现Anaconda真的 ...

  4. 【二分答案+2-SAT】Now or later UVALive - 3211

    题目链接:https://cn.vjudge.net/contest/209473#problem/J 题目大意: 有n架飞机,每架飞机有两个可降落时间点a,b(a<b)(即一架飞机可以选择在时 ...

  5. MySQL Binlog 解析工具 Maxwell 详解

    maxwell 简介 Maxwell是一个能实时读取MySQL二进制日志binlog,并生成 JSON 格式的消息,作为生产者发送给 Kafka,Kinesis.RabbitMQ.Redis.Goog ...

  6. JDBC之批处理

    JDBC之批处理 现在有这么一个需求,要求把2000条记录插入表中,如果使用java代码来操作,我们可以使用Statement或者PreparedStatement来实现,通过循环来把SQL语句一条又 ...

  7. 数据转换bug花了半天时间 Java.math.BigDecimal cannot be cast to java.lang.String

    从数据库取出一个 Count函数 统计的值 在代码中要转成Integer类型的时候 Integer.parseInt((String)map.get("ID_")) 报了一下错误: ...

  8. Linux学习笔记04—IP配置

    一.自动获取IP只有一种情况可以自动获取IP地址,那就是你的Linux所在的网络环境中有DHCP服务.只要你的真机可以自动获取IP,那么安装在虚拟机的Linux同样也可以自动获取IP. 方法很简单,只 ...

  9. ROS知识(22)----USB口映射固定名字

    如果有多个usb链接到电脑,如果插入的先后顺序不同,那么会导致对应的usb口也会不同,例如当只有一个激光的usb链接到电脑,其设备名字为/dev/ttyUSB0:当如果有底盘的usb以及激光的usb连 ...

  10. 通过本地Git部署网站到WebSite

    玩过Azure WebSite(WebApp)的同学应该知道部署网站的方式非常多,今天我要讲的是如果通过本地Git部署网站到WebSite. 1.新建WebSite 创建WebSite非常简单,我这里 ...