UI_UIControl

//

//  ViewController.m

//  UIControl

//

//  Created by HarrySun on 16/7/11.

//  Copyright © 2016 Mobby. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    // 不知道这个怎么写,就拿出来UIButton里面的东西对应着写了些

//    UIButton *button = [UIButton buttonWithType:(UIButtonTypeContactAdd)];    // button 遍历构造器

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 50, 100, 50)];

    

    

    [self.view addSubview:button];

    button.backgroundColor = [UIColor redColor];    // 背景颜色

    [button setTitle:@"按钮" forState:(UIControlStateNormal)];    // 设置标题,未选中时状态

    button.titleLabel.font = [UIFont systemFontOfSize:25];    //设置标题大小

    [button setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)]; // 设置按钮在某个状态下的标题颜色

    [button setTitleColor:[UIColor orangeColor] forState:(UIControlStateHighlighted)];

    button.showsTouchWhenHighlighted = YES; // 设置按钮按下会发光

    button.adjustsImageWhenHighlighted = YES;   // 按下高亮的时候,图像的颜色是否要加深一点

    

    

    

//    button.enabled = NO;   // 设置控件启用

//    button.selected = NO;   // 当用户选择控件时,UIControl类会将selected属性设置为YES

//    button.highlighted = YES;   // 高亮状态

//    button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;  // 控件如何在垂直方向上布置自身的内容

    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;   // 控件如何在水平方向上布置自身的内容

    [button addTarget:self action:@selector(buttonEvent:) forControlEvents:(UIControlEventTouchUpInside)];  // 添加事件

    

    

    

//    [button setImage:[UIImage imageNamed:@"1"] forState:(UIControlStateNormal)];   // 高亮状态下显示图片

    


    button.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);    // 设置按钮的内容内容(包括按钮图片和标题)离按钮边缘上左下右的距离

    button.titleEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10); // 设置按钮的内部标题离按钮边缘上左下右的距离

//    button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);  // 设置按钮的内部图片离按钮边缘上左下右的距离

    

    

    

    

    NSLog(@"%@",button.currentTitle);   // 获取按钮当前标题,只读

    NSLog(@"%@",button.currentAttributedTitle); // 获取按钮当前富文本标题,只读

    NSLog(@"%@",button.currentTitleColor);  // 获取按钮当前标题颜色,只读

    NSLog(@"%@",button.currentTitleShadowColor);    // 获取按钮当前标题的阴影颜色

    NSLog(@"%@",button.currentImage);   // 获取按钮当前图片

    NSLog(@"%@",button.currentBackgroundImage); // 获取按钮当前北京图片

    

    

    

    

}


- (void)buttonEvent:(UIButton *)sender{

    

    NSLog(@"button 点击");

    

    // 取消button已经添加的所有事件

    [sender removeTarget:nil action:nil forControlEvents:(UIControlEventTouchUpInside)];

    

    

    NSSet *myActions = [sender allTargets]; // 获取当前控件上所有指定动作

    NSLog(@"%@",myActions);

    

    

    

    NSArray *myAction = [sender actionsForTarget:self forControlEvent:(UIControlEventValueChanged)];    // 获取某一特定事件目标的全部动作列表

    NSLog(@"%@",myAction);

    

    

    sender.enabled = NO;

    sender.adjustsImageWhenDisabled = YES;   // 按钮被禁用的时候,图像的颜色是否要加深一些(需要按钮有图片才能看出来)

    

    

}



#pragma mark - 重写绘制行为

/*

 

 你可以通过子类化按钮来定制属于你自己的按钮类。在子类化的时候你可以重载下面这些方法,这些方法返回CGRect结构,指明了按钮每一组成部分的边界。

 

 注意:不要直接调用这些方法,这些方法是写给系统调用的

 

 - (CGRect)backgroundRectForBounds:(CGRect)bounds;

 - (CGRect)contentRectForBounds:(CGRect)bounds;

 - (CGRect)titleRectForContentRect:(CGRect)contentRect;

 - (CGRect)imageRectForContentRect:(CGRect)contentRect;

 

 

 */




- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值