美文网首页
UIKit之UIButton

UIKit之UIButton

作者: MI移动 | 来源:发表于2017-07-20 09:49 被阅读0次
#import "TestController.h"

@interface TestController ()
@property (strong, nonatomic)UIButton *btn;
@end

@implementation TestController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    //获取标题
    NSString*s1 = [self.btn titleForState:UIControlStateNormal];
    //获取颜色
    UIColor*color1 = [self.btn titleColorForState:UIControlStateNormal];
}


#pragma mark - lazyload
- (UIButton *)btn{
    if (!_btn) {
        _btn = [UIButton buttonWithType:UIButtonTypeSystem];
        _btn.backgroundColor = [UIColor grayColor];
        // 设置标题
        [_btn setTitle:@"点我啊"forState:UIControlStateNormal];
        [self.view addSubview: _btn];

        //设置前景图片(1.覆盖标题2.不会拉伸3.必须是镂空图)
        //[btn setImage:[UIImage imageNamed:@"2x.png"] forState:UIControlStateNormal];
        //设值背景图片
        //[btn setBackgroundImage:[UIImage imageNamed:@"11"] forState:UIControlStateNormal];
        

        //设置标题颜色
        [_btn setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
        //设置阴影
        [_btn setTitleShadowColor:[UIColor greenColor]forState:UIControlStateNormal];
        
        [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.offset(100);
            make.size.mas_equalTo(CGSizeMake(100, 100));
        }];
        
        [_btn bk_addEventHandler:^(id  _Nonnull sender) {
            NSLog(@"点击了按钮");
        } forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}


@end

相关文章

  • UIKit之UIButton

  • iOS 获取验证码倒计时方法

    import @interface UIButton (YasinTimerCat...

  • 庖丁UIKit之UIButton

    App中最常见的也是基本少不了的交互,就是按钮了。UIKit通过UIButton来提供按钮服务。UIButton的...

  • UIKit之UIButton篇

    1.初始化控件(按钮控件) 方式1:UIButton *etbtn1 = [UIButton alloc]init...

  • UIKit——UIButton

    【译】为避免撕逼,提前声明:本文纯属翻译,仅仅是为了学习,加上水平有限,见谅! UIButton 控制你自定义代码...

  • UIButton困惑

    首先在这里表示在下面引用的作者的文章的感谢。 陈胜华UIKit之UIButton篇基本上已解释UIbutton的属...

  • 设置UIButton内图文位置

    UIButton图片位置 ``` // TitleButton.swift import UIKit class ...

  • UIButton(AFNetworking)扩展说明

    声明处:UIButton+AFNetworking.h 概述 这个分类在UIKit框架的UIButton类添加方法...

  • iOS - Core Graphics

    iOS绘图系统简介 UIKit:最常用的视图框架,如UIView、UIButton等UIKit元素 Core An...

  • UIButton

    UIButton的官方文档https://developer.apple.com/reference/uikit/...

网友评论

      本文标题:UIKit之UIButton

      本文链接:https://www.haomeiwen.com/subject/gjldkxtx.html