iOS开发小白学习体验-8

UISlider

UISlider 就是我们看到的滑动条,让用户能够以可视化的方式设置指定范围内的值。和按钮一样,滑块也能响应事件,还可像文本框一样被读取。如果希望用户对滑块的调整立刻影响应用程序,则需要让他触发操作。

好了废话不说,上代码

self.slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 20)];/**< 初始化 */
    self.slider.backgroundColor = [UIColor yellowColor];/**< 设置slider的背景颜色 */

    self.slider.minimumValue = 0;/**< 设置最小的值 */
    self.slider.maximumValue = 100;/**< 设置最大的值 */
    self.slider.value = 50;/**< 设置初始的值 */

    /**< Tips:下面说的当前值,是slider.value,在UI中显示为:在白色的圈左边的是小于当前值,在白色的圈右边的是大于当前值 */

    self.slider.minimumValueImage = [UIImage imageNamed:@" "];/**< 设置小于当前值的图片 */
    self.slider.maximumValueImage = [UIImage imageNamed:@" "];/**< 设置大于当前值的图片 */

    self.slider.minimumTrackTintColor = [UIColor redColor];/**< 设置小于当前值的颜色 */
    self.slider.maximumTrackTintColor = [UIColor greenColor];/**< 设置大于当前值的颜色 */
    self.slider.thumbTintColor = [UIColor grayColor];/**< 设置滑动圈的颜色 */
    [self.slider addTarget:self action:@selector(sliderByUser) forControlEvents:UIControlEventValueChanged];/**< 设置监听动作,当slider的值发生变化的时候 */

UISwitch

开关(UISwitch)提供了一个简单的开/关UI元素,类似于传统的物理开关,开关的可配置选项很少,应将其用于处理布尔值。我们使用其Value Changed事件来检测开关切换,并通过属性on或实例方法isOn来获取当前值

直接上代码:

/**< 开关的bounds固定为:宽=51,高=31 */
    UISwitch *swt = [[UISwitch alloc]initWithFrame:CGRectMake(0, 60, 0, 0)];
    [self.view addSubview:swt];
    swt.onTintColor = [UIColor redColor];/**< 开关打开时,的填充颜色,默认为绿色 */
    swt.tintColor = [UIColor greenColor];/**< 开关外圈的线的颜色 */
    swt.thumbTintColor = [UIColor blueColor];/**< 开关按钮的颜色 */
    swt.on = YES;/**< 开关是否是打开的(默认为NO) */
    swt.onImage = [UIImage imageNamed:@" "];/**< 开关打开时的图片 */
    swt.offImage = [UIImage imageNamed:@" "];/**< 开关关闭时的图片 */
    [swt addTarget:self action:@selector(switchByUser:) forControlEvents:UIControlEventValueChanged];/**< 给开关监听事件,当值发生变化的时候 */

UIAlertView

UIAlertView就是所谓的”提示框”或者说”警告框”

直接上代码说 :

  • alert的属性
    /**< UIAlertView不需要加载在视图上,显示提示款的方法是show */
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"警告" message:@"我想要个女朋友" delegate:nil cancelButtonTitle:@"不给就揍你" otherButtonTitles:@"送一个林巧雯", nil];/**< 快速创建一个alert,并给其设置标题,信息,取消按钮,其他按钮的文字,设置代理方法 */

    alert.title = @"你想要什么?";/**< 设置提示框的标题 */

    alert.message = @"我想要个女朋友";/**< 设置提示框的信息 */

#warning 为什么UIAlertView挂代理不用遵守UIAlertViewDelegate协议呢?

    alert.delegate = self; /**< 设置代理 */

    NSLog(@"%ld",alert.numberOfButtons);/**< 提示款按钮的数量,这里打印2,这个属性是只读的 */

//    alert.cancelButtonIndex = 3;
    NSLog(@"%ld",alert.cancelButtonIndex);/**< 取消按钮的index,默认情况下,如果没有取消按钮index=-1,如果有取消按钮index=0 */

    NSLog(@"%ld",alert.firstOtherButtonIndex);/**< 如果没有设置其他按钮,那么firstOtherButtonIndex默认为-1,这个属性是只读的 */

    NSLog(@"%d",alert.visible);/**< 提示框是否可见,只读 */

    /**
     *  alertViewStyle 有多种类型
     *  typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
     *      UIAlertViewStyleDefault = 0,      默认情况
     *      UIAlertViewStyleSecureTextInput,  会出现password的输入文本
     *      UIAlertViewStylePlainTextInput,   会出现类似留言的输入文本
     *      UIAlertViewStyleLoginAndPasswordInput   会出现login、password的输入文本
     *  };
     */
    alert.alertViewStyle = UIAlertViewStyleDefault; 


    [alert show];/**< 将alert显示到视图上 */

alert代理方法

- (void)willPresentAlertView:(UIAlertView *)alertView/**< before animation and showing view */ /**< 在动画和显示视图之前调用,第一个被调用 */
{
    NSLog(@"动画还没有出来我就有了");
}

- (void)didPresentAlertView:(UIAlertView *)alertView /**< after animation */ /**< 在动画之后调用,第二个被调用 */
{
    NSLog(@"动画结束了啊?那我出来吧!");
}

// Called when a button is clicked. The view will be automatically dismissed after this call returns
/**< 点击按钮时触发,视图将自动调用之后被返回,第三个被调用 */
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"%ld",buttonIndex);
}

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex /**< before animation and hiding view */ /**< 在隐藏试图和动画之前调用,将要消失,第四个被调用 */
{
    NSLog(@"你们都消失了。。等等我");
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex /**< after animation */ /** 在动画之后调用,已经消失,第五个被调用 */
{
    NSLog(@"终于赶上你们了");
}

// Called after edits in any of the default fields added by the style
/**< 设置是否允许第一个按钮不是取消按钮 */
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    return YES;
}

/**< 当用户按下HOME键的时候,回调此方法,用户点击Cancel按钮的时候不会回调此方法 */
- (void)alertViewCancel:(UIAlertView *)alertView
{
    NSLog(@"我在哪里?");
}

Tips:
1. iOS8 之后就不推荐使用了,现在推荐使用UIAlertController
2. 实现了就叫遵守协议,并不是在<加了才叫遵守>,动态语言特性,关键点在于delegate设置了

UIActionSheet

可以参考banyingli的博客
UIActionSheet的属性

#pragma mark - 属性
    UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"你叫我干嘛" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定?" otherButtonTitles:@"你说谁是小个子", nil];/**< 快速创建一个actionsheet */

    action.title = @" 我是谁 "; /**< 设置标题 */

    action.delegate = self; /**< 挂代理 */

    action.numberOfButtons; /**< 按钮的个数,只读,NSInteger */

    action.cancelButtonIndex; /**< 如果没有实现 "-actionSheetCancel:" 代理方法,我们假装这个按钮已经被点击。默认值为-1 */

    action.destructiveButtonIndex; /**< 设置destructive(红色)按钮。默认的值是-1,-1的意思是没有设置,如果只有一个按钮,这个按钮会被忽略 */

    action.firstOtherButtonIndex; /**< 如果没有设置其他按钮的title,或者没有使用initWithTitle: 方法,那么值为-1 */

    action.visible; /**< 是否可见 */

    /**
     *  actionSheetStyle     
     *  default is UIActionSheetStyleAutomatic. ignored if alert is visible
     *  typedef NS_ENUM(NSInteger, UIActionSheetStyle) {
     *      UIActionSheetStyleAutomatic        = -1,       // take appearance from toolbar style otherwise uses 'default'
     *      UIActionSheetStyleDefault          = UIBarStyleDefault,
     *      UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
     *      UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,
     *  };
     */
    action.actionSheetStyle = UIActionSheetStyleBlackTranslucent;

#pragma mark - 加载到视图上的方法

    [action showInView:self.view];/**< 将actionsheet显示到视图上 */
    /**
     - (void)showFromToolbar:(UIToolbar *)view;
     - (void)showFromTabBar:(UITabBar *)view;
     - (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);
     - (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);
     - (void)showInView:(UIView *)view;
     */

UIActionSheet的代理方法

#pragma mark -- UIActionSheetDelegate --
// Called when a button is clicked. The view will be automatically dismissed after this call returns

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex/**< 点击按钮时被调用,第三个被调用 */
{
    NSLog(@"1");
}

// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button.
// If not defined in the delegate, we simulate a click in the cancel button
/**< 当用户按下home键时调用 */
- (void)actionSheetCancel:(UIActionSheet *)actionSheet
{
    NSLog(@"2");
}

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet// before animation and showing view /**< 在动画和视图显示之前调用,第一个被调用 */
{
    NSLog(@"3");
}
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet// after animation /**< 在动画完成之后调用,第二个被调用 */
{
    NSLog(@"4");
}

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex// before animation and hiding view /**< 点击按钮后,在动画和视图被隐藏之前调用,第四个被调用 */
{
    NSLog(@"5");
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex// after animation /**< 点击按钮后,在动画结束之后调用,第五个被调用 */
{
    NSLog(@"6");
}

UIAlertController

在iOS8之后推荐使用UIAlertController,而不是使用UIAlertView和UIActionSheet

A UIAlertController object displays an alert message to the user. This class replaces the UIActionSheet and UIAlertView classes for displaying alerts. After configuring the alert controller with the actions and style you want, present it using the presentViewController:animated:completion: method.

In addition to displaying a message to a user, you can associate actions with your alert controller to give the user a way to respond. For each action you add using the addAction: method, the alert controller configures a button with the action details. When the user taps that action, the alert controller executes the block you provided when creating the action object. Listing 1 shows how to configure an alert with a single action.


        /**< UIAlertControllerStyleAlert            alert类型
             UIAlertControllerStyleActionSheet      actionSheet类型
         */
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];

        /**<
            handler : 是一个block类型的,在block里面可以写点击按钮时的操作
         */
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];

        /**< addAction:(UIAlertAction)添加一个alertAction,一个alertAction就是一个按钮 */
        [alert addAction:defaultAction];

        /**< UIAlertActionStyleDefault        默认的类型
             UIAlertActionStyleCancel         取消类型
             UIAlertActionStyleDestructive    警告类型(红色的字体加粗)
         */
        UIAlertAction *notDefaultAction = [UIAlertAction actionWithTitle:@"取消取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
            NSLog(@"取消,我就测试一下");
        }];
        [alert addAction:notDefaultAction];

        /**< 你在设置完AlertAction和Style之后,目前用这个方法加载
            类似于UIAlertView里的show方法
            类似于UIActionSheet里的showInView方法
            completion : block类型  block里面的内容与与弹框同时显示
         */
        [self presentViewController:alert animated:YES completion:^{
            NSLog(@"我没有点击吧?");
        }];
深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值