设为首页 加入收藏

TOP

用动画切换按钮的状态(四)
2017-10-13 10:28:45 】 浏览:6903
Tags:动画 切换 按钮 状态
t:(UIFont *)font { _font = font; self.normalLabel.font = font; self.highlightedLabel.font = font; self.disabledLabel.font = font; } - (void)setVerticalOffset:(CGFloat)verticalOffset { _verticalOffset = verticalOffset; CGRect frame = self.normalLabel.frame; frame.origin.x = verticalOffset; self.normalLabel.frame = frame; self.highlightedLabel.frame = frame; self.disabledLabel.frame = frame; } - (void)setHorizontalOffset:(CGFloat)horizontalOffset { _horizontalOffset = horizontalOffset; CGRect frame = self.normalLabel.frame; frame.origin.y = horizontalOffset; self.normalLabel.frame = frame; self.highlightedLabel.frame = frame; self.disabledLabel.frame = frame; } @end

 

控制器源码

//
//  ViewController.m
//  CustomButton
//
//  Created by YouXianMing on 16/5/21.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "ViewController.h"
#import "CustomButton.h"
#import "UIView+SetRect.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    {
        CustomButton *button            = [[CustomButton alloc] initWithFrame:CGRectMake(0, 0, 200, 40.f)];
        button.title                    = @"Heiti TC";
        button.center                   = self.view.center;
        button.y                       -= 100;
        button.font                     = [UIFont fontWithName:@"Heiti TC" size:16.f];
        button.layer.borderWidth        = 0.5f;
        button.layer.borderColor        = [UIColor blackColor].CGColor;
        button.layer.cornerRadius       = 4.f;
        button.layer.masksToBounds      = YES;
        button.buttonEvent              = @selector(buttonsEvent:);
        button.target                   = self;
        button.normalBackgroundColor    = [UIColor blackColor];
        button.highlightBackgroundColor = [UIColor whiteColor];
        button.disabledBackgroundColor  = [UIColor grayColor];
        [button setTitleColor:[UIColor whiteColor] state:BaseControlStateNormal];
        [button setTitleColor:[UIColor blackColor] state:BaseControlStateHighlighted];
        [button setTitleColor:[UIColor whiteColor] state:BaseControlStateDisabled];
        
        [self.view addSubview:button];
        [button changeToState:BaseControlStateNormal animated:NO];
    }
    
    {
        CustomButton *button            = [[CustomButton alloc] initWithFrame:CGRectMake(0, 0, 200, 40.f)];
        button.title                    = @"Heiti TC";
        button.tag                      = 2;
        button.center                   = self.view.center;
        button.y                       += 100;
        button.font                     = [UIFont fontWithName:@"Heiti TC" size:16.f];
        button.layer.borderWidth        = 0.5f;
        button.layer.borderColor        = [UIColor orangeColor].CGColor;
        button.layer.cornerRadius       = 4.f;
        button.layer.masksToBounds      = YES;
        button.buttonEvent              = @selector(buttonsEvent:);
        button.target                   = self;
        button.normalBackgroundColor    = [[UIColor orangeColor] colorWithAlphaComponent:0.95f];
        button.highlightBackgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.65f];
        button.disabledBackgroundColor  = [[UIColor orangeColor] colorWithAlphaComponent:0.45f];
        [button setTitleColor:[UIColor whiteColor] state:BaseControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] state:BaseControlStateHighlighted];
        [button setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.75f] state:BaseControlStateDisabled];
        
        [self.view addSubview:button];
        [butt
首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【原】iOS学习之KVC原理 下一篇【代码笔记】iOS-设置textView或..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目