IOS开发学习第四章---使用更多的UI控件

这一章介绍了一些基本的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;

对于switch button
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属性可以是自己也可以是下一个控件。
就是让自己或下一个控件帮你做一个什么事儿。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值