ios成长之每日一遍(day 3)
今天要介绍一下更多的控键使用, 当然也会对上一篇说的控件做一个巩固, 所以这一篇涉及到的控键会包括 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)的更多相关文章
- ios成长之每日一遍(day 8)
这几天都有一些任务要跟, 把ios的学习拉后, 看看要抓紧咯, 看看轮到的学习的是UITableView. BIDAppDelegate.h #import <UIKit/UIKit.h> ...
- ios成长之每日一遍(day 5)
iOS 屏幕方向那点事儿http://zhenby.com/blog/2013/08/20/talk-ios-orientation/ 针对当前的屏幕方向进行对应的代码布局 BIDViewContro ...
- ios成长之每日一遍(day 1)
Hello world开始. 这里不讨论如何创建项目导入项目.由于趁上班时间打酱油所以也不谈细节, 只谈具体项目的实现与关键流程的解析, 只供本人实际程况使用.不喜请移驾. 首先来谈谈 AppDele ...
- ios成长之每日一遍(day 7)
今天到UITabBarController 结合 UIPickView, 这里一共有5个实现, 由浅到易. 其实在IB上面使用UITabBarController很简单, 就像平常拖控件一样拖到界面上 ...
- ios成长之每日一遍(day 6)
toolBar上的View Switcher BIDAppDelegate.h #import <UIKit/UIKit.h> @class BIDSwitchViewController ...
- ios成长之每日一遍(day 4)
今天, 主要讲四种常见的问题, 废话不多说了, 直接开始. 自动布局:这个我发现有一篇文章写得非常好, 直接表明出地http://www.cocoachina.com/applenews/devnew ...
- ios成长之每日一遍(day 2)
接着下来简单说说Label(相当于android的textview)和button的使用, 由于都是与上篇的AppDelegate一致, 所以这一篇就说说ViewController与xib的使用呗. ...
- iOS:从头捋一遍VC的生命周期
一.介绍 UIViewController是iOS开发中的核心控件,没有它那基本上任何功能都无法实现,虽然系统已经做了所有控件的生命维护,但是,了解它的生命周期是如何管理还是非常有必要的.网上有很多教 ...
- IOS成长之路-用NSXMLParser实现XML解析
再次对xml进行解析,又有了些理解,如果有不对的地方,请给小弟指出,谢谢! <?xml version="1.0" encoding="UTF-8"?&g ...
随机推荐
- Linux下配置MySQL需要注意的几点
1.为mysql加上连接数,linux下最大能允许8000个mysql连接. 经验下,设置为3000 [mysqld] max_connections=3000
- Sublime Text 中open in browser /view in browser 无反应
问题 早上用Sublime Text写html的时候,发现右键的open in browser或view in browser命令都突然无法使用了,无法像以前一样在浏览器打开编写的页面了. 开始以为是 ...
- 【笔试题】在 Java 中,如何跳出当前的多重嵌套循环?
笔试题 在 Java 中,如何跳出当前的多重嵌套循环? public class Demo { public static void main(String[] args) { System.out. ...
- Spark中hashshuffle与sortshuffle
在spark1.2以上的版本中,默认shuffle的方式已经变成了sortshuffle(在spark.shuffle.manager修改org.apache.spark.shuffle.sort.H ...
- 016 jquery中html与val得到使用
1.属性操作 2.设置html . 3.程序(关于html) <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- php返回上一页
echo "<script>alert('没有获取到订单信息');history.go(-1);</script>";
- 【BZOJ 1211】 1211: [HNOI2004]树的计数 (prufer序列、计数)
1211: [HNOI2004]树的计数 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2468 Solved: 868 Description 一 ...
- MyBatis3与Spring3无缝集成-从iBatis平滑过渡
从2010开始接触iBatis到现在,一直到现在把iBatis作为数据访问层ORM.为了演示一个Web应用,今天又搭了个SpringMVC应用,由于应用比较简单,Spring版本直接用最新版本3.2. ...
- C语言程序设计I—寒假作业
20188480 http://www.cnblogs.com/arthur-w/
- phpexcel导出excel等比例缩放图片
list($width, $height, $type, $attr) = getimagesize($img_path); if( $width>100 || $height >100 ...