IOS自动化过程与给元素定义唯一ID

IOS自动化过程与给元素定义唯一ID

经尝试,发现IOS常用控件(UIButton、UITextField、UIImage、UISlider、UISwitch、UITableViewCell、UILabel)
如果需要添加ID 只需要一行代码即可,不影响逻辑且不影响显示:实例如下
btn.accessibilityLabel = @"refreshbutton";
ID添加尽量在同一个页面中 重要元素不要有相同即可
这对自动化的精确写作、精确执行帮助较大  
几种常用控件初始化如下:


UIButton *btn;
    btn = [[UIButton alloc]initWithFrame:CGRectMake(20, 335, 80, 20)];
    btn.accessibilityLabel = @"refreshbutton";
    btn.backgroundColor = [UIColor greenColor];
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(refresh) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    UITextField *text;
    text = [[UITextField alloc]initWithFrame:CGRectMake(170, 335, 180, 20)];
    text.placeholder = @"这是一个输入框";
    text.accessibilityLabel = @"inputtext01";
    text.textColor = [UIColor redColor];
    text.secureTextEntry = YES;
    [self.view addSubview:text];
    
    UIImage * image =[UIImage imageNamed:@"icon.png"];
    UIImageView * imageview = [[UIImageView alloc]initWithFrame:CGRectMake(20, 360, 80, 20)];
    imageview.accessibilityLabel = @"imagetype01";
    imageview.backgroundColor = [UIColor blueColor];
    imageview.image = image;
    [self.view addSubview:imageview];
    
    UISlider * slider;
    slider = [[UISlider alloc]initWithFrame:CGRectMake(170, 360, 80, 20)];
    slider.accessibilityLabel = @"slider01";
    [self.view addSubview:slider];
    
    UISwitch * switc;
    switc = [[UISwitch alloc]initWithFrame:CGRectMake(20, 385, 80, 20)];
    switc.accessibilityLabel = @"switc01";
    [self.view addSubview:switc];
    
    UITableViewCell * cell;
    cell = [[UITableViewCell alloc]initWithFrame:CGRectMake(170, 385, 80, 20)];
    cell.accessibilityLabel = @"cell01";
    cell.textLabel.text = @"这是一个cell";
    [self.view addSubview:cell];


    
    UILabel *label;
    label = [[UILabel alloc] initWithFrame:CGRectMake(20, 35, 150, 20)];
    label.text = @"平台型号:";
    label.accessibilityLabel = @"platformshap";
    [self.view addSubview:label];
    [label release];

    

    

  UISearchBar *searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(30, 0, 200, 44)];

  - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {

    UITextField *searchBarTextField = nil;

    NSArray *views = ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) ? searchBar.subviews:[[searchBar.subviews                          objectAtIndex:0] subviews];

    for (UIView *subview in views) {

        if ([subview isKindOfClass:[UITextField class]]) {

            searchBarTextField = (UITextField *)subview;

            break;

        }

    }

    searchBarTextField.accessibilityLabel = @"CustomerManagerSearch";

    searchBarTextField.enablesReturnKeyAutomatically = YES;

  }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值