首页 > 其他 > 详细

oc UIButton

时间:2015-04-17 18:24:18      阅读:507      评论:0      收藏:0      [点我收藏+]


#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;

}

oc UIButton

原文:http://blog.csdn.net/zx6268476/article/details/45097865

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!