xcode快捷创建控件

本文介绍了使用Xcode快速创建UIImageView、UILabel、UIButton以及UITableView的方法,包括设置属性、添加目标动作以及实现数据源和代理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.快捷创建ImageView
UIImageView *<#imageViewName#> = [[UIImageView alloc] initWithFrame:CGRectMake(<#x#>, <#y#>, <#width#>, <#height#>)];
<#imageViewName#>.layer.masksToBounds = YES;
<#imageViewName#>.layer.cornerRadius = <#imageViewName#>.width/2;
<#imageViewName#>.image = [UIImage imageNamed:@"<#imageName#>"];
[self addSubview:<#imageViewName#>];

2.快捷创建Iabel
UILabel *<#labelName#> = [[UILabel alloc] initWithFrame:CGRectMake(<#x#>, <#y#>, <#width#>, <#height#>)];
<#labelName#>.textColor = <#textColor#>;
<#labelName#>.font = [UIFont systemFontOfSize:
16];
<#labelName#>.textAlignment = NSTextAlignmentCenter;
[self addSubview:<#labelName#>];


3.快捷创建UIButton
UIButton *<#buttonName#> = [[UIButton alloc]initWithFrame:CGRectMake(<#x#>, <#y#>, <#width#>, <#height#>)];
[<#buttonName#> setTitleColor:<#titleColor#> forState:UIControlStateNormal];
[<#buttonName#> setTitle:
@"" forState:UIControlStateNormal];
<#buttonName#>.titleLabel.font = [UIFont systemFontOfSize:<#fontSize#>];
[<#buttonName#> addTarget:
self action:@selector(startTime:) forControlEvents:UIControlEventTouchUpInside];
<#buttonName#>.layer.cornerRadius =
2;
<#buttonName#>.layer.masksToBounds =
YES;
<#buttonName#>.backgroundColor = <#color#>;
[self.view addSubview:<#buttonName#>];

4.快捷创建属性
/**
 *  <#
注释#>
 */
@property (nonatomic,strong) <#class#> *<#name#>;


5.快捷创建table
-(UITableView *)<#tableName#>{
   
   
if (!_<#tableName#>) {
        _<#tableName#> = [[UITableView alloc] initWithFrame:CGRectMake(
0, 0, kScreenWith, kScreenHeight) style:UITableViewStylePlain];
        _<#tableName#>.dataSource =
self;
        _<#tableName#>.delegate =
self;
        _<#tableName#>.rowHeight = <#rowHeight#>;
        _<#tableName#>.tableHeaderView = <#headView#>;
        _<#tableName#>.tableFooterView = [[UIView alloc] init];
    }
   
return _<#tableName#>;
}


6.快捷创建table数据源
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
   
return <#arrayName#>.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
   
static NSString *identifier = @"cell";
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
   
   
if (!cell) {
       
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
       
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    }
   
    cell.model = <#arrayName#>[indexPath.row];
   
   
return cell;
   
}

7.快捷创建table代理
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
    [tableView deselectRowAtIndexPath:indexPath animated:
YES];
   
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值