这一章介绍了一些基本的UI控件以及详细介绍了每个UI控件中各种属性的用法。
设计UI控件有:
- UIImageView
- UITextField
- UIButton
- Slider
- Switch
- UIView
- ActionSheet
- Alert
小实例长这样:
涉及知识点:
1. 虚拟键盘的关闭
对应不同的虚拟键盘,有不同的键盘关闭方法。
有Done按钮的,没有Done按钮的处理方式不同
有Done按钮的:
绑定textField的‘Did end on Exit'事件去一个BIAction,
[sender resignFirstResponder];没有Done按钮的,如数字键盘
绑定textField父控件,也就是UIView
设置UIView的控件Class 为’UIControl'
然后绑定它的‘Touch up' 事件,关闭代码同上面。这样做以后,点击背景即可关闭虚拟键盘。
2. 如何获取控件的改变
对于slider
int progress = lroundf(sender.value);对于switch
BOOL setting = sender.isOn;
if (sender.selectedSegmentIndex == 0) {
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;
}
3. 如何控制隐藏与显示
见上面。
4. 如何打开ActionSheet 和获取用户的决定
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No Way!"
destructiveButtonTitle:@"Yes, I’m Sure!"
otherButtonTitles:nil];
[actionSheet showInView:self.view];if (buttonIndex != [actionSheet cancelButtonIndex]) {
NSString *msg = nil;
if ([self.nameField.text length] > 0) {
msg = [NSString stringWithFormat:
@"You can breathe easy, %@, everything went OK.",
self.nameField.text];
} else {
msg = @"You can breathe easy, everything went OK.";
}
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Something was done"
message:msg
delegate:self
cancelButtonTitle:@"Phew!"
otherButtonTitles:nil];
[alert show];
}
5. 如何使用alert显示消息
见上面
难点:
1. 理解delegate (个人理解,可能有误,还在完善中)
有些控件需要使用delegate才可以让它显示出来和使用。
首先需要在相应的控件类中声明需要用到的delegate协议。
@interface BIDViewController : UIViewController <UIActionSheetDelegate>然后使用协议中特定的方法显示和使用控件。
控件中的delegate属性可以是自己也可以是下一个控件。
就是让自己或下一个控件帮你做一个什么事儿。
本章节深入探讨了iOS应用中基本UI控件的使用及虚拟键盘的关闭方法,包括滑动条、开关、视图等元素的属性与交互,并提供了获取控件状态变化的实现方式,同时介绍了如何通过ActionSheet与Alert进行用户决策收集。
3676

被折叠的 条评论
为什么被折叠?



