2016年01月06日,07日,08日公司项目开发记录

UISwitch 控件


自定义 cell 

首先现在viewDidLoad中声明这个 cell

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.tableView registerNib:[UINib nibWithNibName:@"SKUserRelativesTableViewCell" bundle:nil] forCellReuseIdentifier:@"SKUserRelatives"];
}
只在在代理方法中设置重用标示符
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *identifier = @"SKUserRelatives";
    SKUserRelativesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[SKUserRelativesTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
    }
    cell.textLabel.text = @"测试";
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

自己创建自己的 cell

.h

#import <UIKit/UIKit.h>

@interface SKUserRelativesTableViewCell : UITableViewCell{

    UILabel *userName;

    UISwitch *switch_1;

    UISwitch *switch_2;

}
@end


.m


<span style="font-size:18px;">#import "SKUserRelativesTableViewCell.h"

@interface SKUserRelativesTableViewCell ()

@end

@implementation SKUserRelativesTableViewCell

-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self layoutLabel];
    }
    return self;
}
-(void)layoutLabel{
    userName = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 100, 100)];
    [self.contentView addSubview:userName];

    switch_1 = [[UISwitch alloc]initWithFrame:CGRectMake(SKScreenWidth / 2 + 15 ,5 , 100, 100)];
    [switch_1 addTarget:self action:@selector(change:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:switch_1];


    switch_2 = [[UISwitch alloc]initWithFrame:CGRectMake(SKScreenWidth * 3 / 4 + 15,5 ,100, 100)];
    [switch_2 addTarget:self action:@selector(change:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:switch_2];

}

-(void)change:(id)sender{
    UISwitch *switch_BT = (UISwitch *)sender;
    BOOL isON = [switch_BT isOn];
    if (isON) {
        NSLog(@"yes");
    }
    else{
        NSLog(@"no");
    }
}
@end</span>


更多精彩文章,尽在我的公众号.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值