iOS开发学习之路【UI界面】——视图分类、UIButton、UIActionSheet、UIAlertView

视图介绍

  1. 视图时界面上的矩形构建块;
  2. 一个应用经常由若干个视图组合而成;
  3. 使用视图的目的:
    1. 展示应用的内容
    2. 导航视图

视图的分类

  1. view 大部分视图只是用来呈现,而内容不可以编辑
  2. controls 可以和用户进行交互,内容可以编辑

UIButton 简介

​ UIButton 时 iOS 中最常见的视图空间,常用来响应用户的点击事件。事件方法定义了要完成的功能。

使用IB实现

在这里插入图片描述

助手编辑器 Ctrl + 左键 拖拽生成

使用代码实现

#import "ViewController.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIButton *mybutton;
//代码创建
@property (strong, nonatomic) IBOutlet UIButton *mybutton2;
@end

@implementation ViewController
- (IBAction)click:(id)sender {
    NSLog(@"click");
}
- (IBAction)click2:(UIButton *)sender forEvent:(UIEvent *)event {
    NSLog(@"click2...");
}
- (IBAction)custom:(id)sender{
    NSLog(@"custom...");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    代码实现 状态属性
    self.mybutton2 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.mybutton2.frame = CGRectMake(30, 30, 100, 200);
    [self.mybutton2 setTitle:@"Login..." forState:UIControlStateNormal];
//    添加按钮
    [self.view addSubview:self.mybutton2];
    
//    target - action 响应事件
    [self.mybutton2 addTarget:self action:@selector(custom:) forControlEvents:UIControlEventTouchUpInside];
}


@end

在这里插入图片描述

UIActionSheet 简介

‘UIActionSheet’ is deprecated: first deprecated in iOS 8.3 - UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead

已经被废弃不在使用了,用UIAlertController代替!

​ UIActionSheet 和 UIAlertView 用法类似,区别在于 UIActionSheet 为用户提供了多个可选项,并且 UIActionSheet 需要指出它出现的位置。

创建 实现代理

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIActionSheetDelegate>

@end
- (IBAction)showActionSheet:(id)sender {
    //    UIActionSheet
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"Test ActionSheet" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"destruct" otherButtonTitles:@"Other ",@"Other2",@"Other3", nil];
    [sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 8_3) __TVOS_PROHIBITED{
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
    NSLog(@"%@", title);
}

在这里插入图片描述

UIAlertView 简介

​ UIAlertView 视图为用户显示一个提示信息,例如:要求用户确认某个决定;从用户获得一些信息,例如:用户登录等。

创建 实现代理

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIAlertViewDelegate>

@end
- (IBAction)showAlert:(id)sender {
//    NSLog(@"showAlert");
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK1",@"OK2", nil];
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0){
    switch(buttonIndex){
        case 0:
            NSLog(@"Cancel");
            break;
        case 1:
            NSLog(@"OK1");
            break;
        case 2:
            NSLog(@"OK2");
            break;
        default:
            break;
    }
}

在这里插入图片描述

自动以样式

typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
    UIAlertViewStyleDefault = 0, 		//默认样式
    UIAlertViewStyleSecureTextInput,	//密码输入框
    UIAlertViewStylePlainTextInput,		//平台文件输入框
    UIAlertViewStyleLoginAndPasswordInput	//登录框
} __TVOS_PROHIBITED;

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值