美文网首页
UIButton.h

UIButton.h

作者: ShenYj | 来源:发表于2016-09-04 20:57 被阅读103次
    //
    //  UIButton.h
    //  UIKit
    //
    //  Copyright (c) 2005-2013, Apple Inc. All rights reserved.
    //
    
    @class UIImage, UIFont, UIColor, UIImageView, UILabel;
    
    typedef NS_ENUM(NSInteger, UIButtonType) {
        UIButtonTypeCustom = 0,                         // 无样式,用户调整
        UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // 系统标准样式
    
        UIButtonTypeDetailDisclosure, // 圈圈 i 样式
        UIButtonTypeInfoLight,        // 圈圈 i 样式
        UIButtonTypeInfoDark,         // 圈圈 i 样式
        UIButtonTypeContactAdd,       // 圈圈 + 样式
        
        UIButtonTypeRoundedRect = UIButtonTypeSystem,   // 淘汰,用 UIButtonTypeSystem 替代
    };
    
    NS_CLASS_AVAILABLE_IOS(2_0) @interface UIButton : UIControl <NSCoding> {
      @private // 私有的
        CFMutableDictionaryRef _contentLookup;
        UIEdgeInsets           _contentEdgeInsets;  // 内容的内边距
        UIEdgeInsets           _titleEdgeInsets;    // 标题的内边距
        UIEdgeInsets           _imageEdgeInsets;    // 图片的内边距
        
        UIImageView           *_backgroundView;      // 内部的背景图片控件
        UIImageView           *_imageView;           // 内部的图片控件
        UILabel               *_titleView;           // 内部的标题
        
        BOOL                   _initialized;
        UIControlState         _lastDrawingControlState;
        struct {
            unsigned int reversesTitleShadowWhenHighlighted:1;
            unsigned int adjustsImageWhenHighlighted:1;
            unsigned int adjustsImageWhenDisabled:1;
            unsigned int autosizeToFit:1;
            unsigned int disabledDimsImage:1;
            unsigned int showsTouchWhenHighlighted:1;
            unsigned int buttonType:8;
            unsigned int shouldHandleScrollerMouseEvent:1;
            unsigned int titleFrozen:1;
        } _buttonFlags;
    }
    
    + (id)buttonWithType:(UIButtonType)buttonType;
    
    @property(nonatomic)          UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // 内容缩进
    @property(nonatomic)          UIEdgeInsets titleEdgeInsets;                // 文字标题缩进
    @property(nonatomic)          BOOL         reversesTitleShadowWhenHighlighted; // 默认 NO. 高亮时,阴影反转
    @property(nonatomic)          UIEdgeInsets imageEdgeInsets;                // 图片缩进
    
    @property(nonatomic)          BOOL         adjustsImageWhenHighlighted;    // default is YES. if YES, image is drawn darker when highlighted(pressed)
    @property(nonatomic)          BOOL         adjustsImageWhenDisabled;       // default is YES. if YES, image is drawn lighter when disabled
    @property(nonatomic)          BOOL         showsTouchWhenHighlighted;      // 点击时按钮中间现实白色的高亮
    @property(nonatomic,retain)   UIColor     *tintColor NS_AVAILABLE_IOS(5_0); // The tintColor is inherited through the superview hierarchy. See UIView for more information.
    @property(nonatomic,readonly) UIButtonType buttonType;
    
    # 设置内部子控件的属性
    - (void)setTitle:(NSString *)title forState:(UIControlState)state; # 字体
    - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; #字体颜色
    - (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; # 阴影
    - (void)setImage:(UIImage *)image forState:(UIControlState)state;
    - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
    - (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state NS_AVAILABLE_IOS(6_0);
    
    # 这些 getters 方法只返回一种状态的值
    - (NSString *)titleForState:(UIControlState)state;
    - (UIColor *)titleColorForState:(UIControlState)state;
    - (UIColor *)titleShadowColorForState:(UIControlState)state;
    - (UIImage *)imageForState:(UIControlState)state;
    - (UIImage *)backgroundImageForState:(UIControlState)state;
    - (NSAttributedString *)attributedTitleForState:(UIControlState)state NS_AVAILABLE_IOS(6_0);
    
    # 当按钮的状态改变时,这些值会自动改变,只有get方法,只读的
    @property(nonatomic,readonly,retain) NSString *currentTitle;             // 可以为空
    @property(nonatomic,readonly,retain) UIColor  *currentTitleColor;        // 默认是white(1,1) ,不能为空
    @property(nonatomic,readonly,retain) UIColor  *currentTitleShadowColor;  // default is white(0,0.5).
    @property(nonatomic,readonly,retain) UIImage  *currentImage;             // 可以为空
    @property(nonatomic,readonly,retain) UIImage  *currentBackgroundImage;   // 可以为空
    @property(nonatomic,readonly,retain) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0); # 可以为空
    
    # return title and image views. will always create them if necessary. always returns nil for system buttons
    @property(nonatomic,readonly,retain) UILabel     *titleLabel NS_AVAILABLE_IOS(3_0);
    @property(nonatomic,readonly,retain) UIImageView *imageView  NS_AVAILABLE_IOS(3_0);
    
    
    #pragma - mark 自定义按钮,重写这些方法调整按钮内部子控件的尺寸
    - (CGRect)backgroundRectForBounds:(CGRect)bounds;
    - (CGRect)contentRectForBounds:(CGRect)bounds;
    - (CGRect)titleRectForContentRect:(CGRect)contentRect;
    - (CGRect)imageRectForContentRect:(CGRect)contentRect;
    
    @end
    
    # 已经失效
    @interface UIButton(UIButtonDeprecated)
    
    @property(nonatomic,retain) UIFont         *font              NS_DEPRECATED_IOS(2_0, 3_0); // 字体
    @property(nonatomic)        NSLineBreakMode lineBreakMode     NS_DEPRECATED_IOS(2_0, 3_0); //
    @property(nonatomic)        CGSize          titleShadowOffset NS_DEPRECATED_IOS(2_0, 3_0);
    
    @end
    
    

    相关文章

      网友评论

          本文标题:UIButton.h

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