Day2

1  Button 手写代码生产的方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-(void)viewDidLoad
{
    [super viewDidLoad];
     
    UIButton *btn = [[UIButton alloc]init];
    btn.frame = CGRectMake(0, 100, 100, 100);
    [btn setTitle:@"click" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
     
    UIImage *image = [UIImage imageNamed:@"btn_01"];
    [btn setBackgroundImage:image forState:UIControlStateNormal];
     
    [btn setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];
     
    [self.view addSubview:btn];
     
}

  

1
2
//添加button点击事件  self.click方法
[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

 

1
self.headImageView = btn;//相当于连线 监听方法连线

2 Label  Image Button 手写代码生成以及其他属性的设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
     
    //标签描述
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 320, 40)];
    label.text = @"1/5";
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    self.noLabel = label;
     
    //图片
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 70, 200, 200)];
    imageView.image = [UIImage imageNamed:@"biaoqingdi"];
    [self.view addSubview:imageView];
    self.icon = imageView;
     
    //图片描述
    UILabel *iconLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 300, 320, 80)];
    iconLabel.text = @"什么表情都弱爆了";
    iconLabel.textAlignment = NSTextAlignmentCenter;//居中
    [self.view addSubview:iconLabel];
    self.descriptionLabel = iconLabel;
     
    //left icon
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    leftBtn.center = CGPointMake(self.icon.frame.origin.x/2, self.icon.center.y);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal];
    [self.view addSubview:leftBtn];
    self.leftButton = leftBtn;
     
    //right btn
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    rightBtn.center = CGPointMake(self.view.frame.size.width- self.icon.frame.origin.x/2, self.icon.center.y);
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"right_normal"] forState:UIControlStateNormal];
    [self.view addSubview:rightBtn];
    self.leftButton = rightBtn;
}

  

 

posted @   菠萝君  阅读(139)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示