UIButton使用介绍

来源:互联网 发布:达拉斯2000年人口数据 编辑:程序博客网 时间:2024/06/07 04:11
       self.addFan = [[UIButton alloc]initWithFrame:CGRectMake(498/2, 184/2, 120/2-1, 48/2)];
        self.addFan.backgroundColor = [UIColor clearColor];
        //按钮背景图
        [self.addFan setBackgroundImage:[UIImage imageNamed:@"Click-the-button-is-not.png"] forState:UIControlStateNormal];
        //按钮文字颜色
        [self.addFan setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        //按钮文字类型大小
        [self.addFan.titleLabel setFont: [UIFont systemFontOfSize: 10.0]];
        //按钮文字内容
        [self.addFan setTitle:@"关注" forState:UIControlStateNormal];
        //按钮文字的偏移位置
        [self.addFan setTitleEdgeInsets:UIEdgeInsetsMake(13/2,5, 13/2, 0)];
        //按钮图片
        [self.addFan setImage:[UIImage imageNamed:@"Attention-symbol.png"] forState:UIControlStateNormal];
        //按钮图片偏移位置
        [self.addFan setImageEdgeInsets:UIEdgeInsetsMake(15/2,28/2, 15/2, 120/2-1-18/2-28/2)];
        [self.addFan addTarget:self action:@selector(addFan:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.addFan];