oc UIButton


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    // 1.UIButton

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];// 自定义button,现在oc追求扁平化,有些效果

    button.frame = CGRectMake(self.view.frame.size.width/2.0-100/2.0, 150, 100, 45) ;

    [button setTitle:@"未收藏" forState:UIControlStateNormal];

    [button setTitle:@"已收藏" forState:UIControlStateSelected];

    [button setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];

    button.backgroundColor = [UIColor brownColor];

//    button.highlighted = YES;

//    button.enabled = YES;

    [button addTarget:self action:@selector(changeImage) forControlEvents:UIControlEventTouchUpInside];

    

    [self.view addSubview:button];

    button.tag = 101;

    button.showsTouchWhenHighlighted  = YES;// 点上去发一下光

    

    //改字体大小

    button.titleLabel.font = [UIFont systemFontOfSize:30];

    

    //设置图片

    UIImage * image = [UIImage imageNamed:@"010@2x"];

    [button setImage:image forState:UIControlStateSelected];

    

    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight ;// 右对齐

    

    UIEdgeInsets Imageinset = {0,10,0,0};// 上左下右

    [button setImageEdgeInsets:Imageinset];

    

    UIEdgeInsets titleInset = {0,20,20,0};

    [button setTitleEdgeInsets:titleInset];

    

    

    

}





- (void)changeImage{

    UIButton * btn =(UIButton *)[self.view viewWithTag:101];

    btn.selected = !btn.selected;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值