UIButton属性

  1 //

  2 //  UIButton1.h

  3 //  UIKit

  4 //http://blog.163.com/fuxiaohui@126/blog/static/131745826201172601821628/

  5 //  Copyright (c) 2005-2013, Apple Inc. All rights reserved.

  6 //

  7 

  8 #import <Foundation/Foundation.h>

  9 #import <UIKit/UIControl.h>

 10 #import <UIKit/UIGeometry.h>

 11 #import <UIKit/UIStringDrawing.h>

 12 #import <UIKit/UIKitDefines.h>

 13 

 14 @class UIImage, UIFont, UIColor, UIImageView, UILabel;

 15 

 16 //button类型

 17 typedef NS_ENUM(NSInteger, UIButtonType) {

 18     UIButtonTypeCustom = 0,        //自定义                 // no button type

 19     UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // standard system button

 20     

 21     UIButtonTypeDetailDisclosure,

 22     UIButtonTypeInfoLight,

 23     UIButtonTypeInfoDark,

 24     UIButtonTypeContactAdd,

 25     

 26     UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated(已过时), use UIButtonTypeSystem instead(代替)

 27 };

 28 

 29 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIButton : UIControl <NSCoding> {

 30 @private

 31     //Edge n. 边缘;  inset  vt. 嵌入;插入

 32     //UIEdgeInsets==>这货其实就是插入间隔区域。正值表示间隔值,负值表示超出参照物的距离。

 33     //UIEdgeInsets insets = {top, left, bottom, right};  默认都为0

 34     CFMutableDictionaryRef _contentLookup;

 35     UIEdgeInsets           _contentEdgeInsets;

 36     UIEdgeInsets           _titleEdgeInsets;

 37     UIEdgeInsets           _imageEdgeInsets;

 38     UIImageView           *_backgroundView;

 39     UIImageView           *_imageView;

 40     UILabel               *_titleView;

 41     BOOL                   _initialized;

 42     UIControlState         _lastDrawingControlState;

 43     struct {

 44         unsigned int reversesTitleShadowWhenHighlighted:1;

 45         unsigned int adjustsImageWhenHighlighted:1;

 46         unsigned int adjustsImageWhenDisabled:1;

 47         unsigned int autosizeToFit:1;

 48         unsigned int disabledDimsImage:1;

 49         unsigned int showsTouchWhenHighlighted:1;

 50         unsigned int buttonType:8;

 51         unsigned int shouldHandleScrollerMouseEvent:1;

 52         unsigned int titleFrozen:1;

 53     } _buttonFlags;

 54 }

 55 

 56 + (id)buttonWithType:(UIButtonType)buttonType;

 57 ////默认为UIEdgeInsetsZero

 58 @property(nonatomic)          UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero

 59 @property(nonatomic)          UIEdgeInsets titleEdgeInsets;                // default is UIEdgeInsetsZero

 60 //默认为NO.如果为YES,当按钮的状态进行切换时,文本的影子会反转

 61 @property(nonatomic)          BOOL         reversesTitleShadowWhenHighlighted; // default is NO. if YES, shadow reverses to shift between engrave and emboss appearance

 62 @property(nonatomic)          UIEdgeInsets imageEdgeInsets;                // default is UIEdgeInsetsZero

 63 //默认为YES.如果为YES,当按钮状态为高亮时,图像变暗

 64 @property(nonatomic)          BOOL         adjustsImageWhenHighlighted;    // default is YES. if YES, image is drawn darker when highlighted(pressed)

 65 //默认为YES.如果为YES,当按钮状态为禁用时,图像变暗

 66 @property(nonatomic)          BOOL         adjustsImageWhenDisabled;       // default is YES. if YES, image is drawn lighter when disabled

 67 //默认为NO.如果为YES, 当按钮状态为高亮时,显示一个简单的反馈(类似于光环)

 68 @property(nonatomic)          BOOL         showsTouchWhenHighlighted;      // default is NO. if YES, show a simple feedback (currently a glow) while highlighted

 69 @property(nonatomic,retain)   UIColor     *tintColor NS_AVAILABLE_IOS(5_0); // The tintColor is inherited through the superview hierarchy. See UIView for more information.

 70 @property(nonatomic,readonly) UIButtonType buttonType;

 71 

 72 // you can set the image, title color, title shadow color, and background image to use for each state. you can specify data

 73 // for a combined state by using the flags added together. in general, you should specify a value for the normal state to be used

 74 // by other states which don't have a custom value set

 75 

 76 - (void)setTitle:(NSString *)title forState:(UIControlState)state;                     // default is nil. title is assumed to be single line

 77 - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default if nil. use opaque white

 78 - (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil. use 50% black

 79 - (void)setImage:(UIImage *)image forState:(UIControlState)state;                      // default is nil. should be same size if different for different states

 80 - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil

 81 - (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state NS_AVAILABLE_IOS(6_0); // default is nil. title is assumed to be single line

 82 

 83 - (NSString *)titleForState:(UIControlState)state;          // these getters only take a single state value

 84 - (UIColor *)titleColorForState:(UIControlState)state;

 85 - (UIColor *)titleShadowColorForState:(UIControlState)state;

 86 - (UIImage *)imageForState:(UIControlState)state;

 87 - (UIImage *)backgroundImageForState:(UIControlState)state;

 88 - (NSAttributedString *)attributedTitleForState:(UIControlState)state NS_AVAILABLE_IOS(6_0);

 89 

 90 // these are the values that will be used for the current state. you can also use these for overrides. a heuristic will be used to

 91 // determine what image to choose based on the explict states set. For example, the 'normal' state value will be used for all states

 92 // that don't have their own image defined.

 93 

 94 @property(nonatomic,readonly,retain) NSString *currentTitle;             // normal/highlighted/selected/disabled. can return nil

 95 @property(nonatomic,readonly,retain) UIColor  *currentTitleColor;        // normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1)

 96 @property(nonatomic,readonly,retain) UIColor  *currentTitleShadowColor;  // normal/highlighted/selected/disabled. default is white(0,0.5).

 97 @property(nonatomic,readonly,retain) UIImage  *currentImage;             // normal/highlighted/selected/disabled. can return nil

 98 @property(nonatomic,readonly,retain) UIImage  *currentBackgroundImage;   // normal/highlighted/selected/disabled. can return nil

 99 @property(nonatomic,readonly,retain) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0);  // normal/highlighted/selected/disabled. can return nil

100 

101 // return title and image views. will always create them if necessary. always returns nil for system buttons

102 @property(nonatomic,readonly,retain) UILabel     *titleLabel NS_AVAILABLE_IOS(3_0);

103 @property(nonatomic,readonly,retain) UIImageView *imageView  NS_AVAILABLE_IOS(3_0);

104 

105 // these return the rectangle for the background (assumes bounds), the content (image + title) and for the image and title separately. the content rect is calculated based

106 // on the title and image size and padding and then adjusted based on the control content alignment. there are no draw methods since the contents

107 // are rendered in separate subviews (UIImageView, UILabel)

108 

109 - (CGRect)backgroundRectForBounds:(CGRect)bounds;

110 - (CGRect)contentRectForBounds:(CGRect)bounds;

111 - (CGRect)titleRectForContentRect:(CGRect)contentRect;

112 - (CGRect)imageRectForContentRect:(CGRect)contentRect;

113 @end

114 

115 @interface UIButton(UIButtonDeprecated)

116 

117 @property(nonatomic,retain) UIFont         *font              NS_DEPRECATED_IOS(2_0, 3_0);

118 @property(nonatomic)        NSLineBreakMode lineBreakMode     NS_DEPRECATED_IOS(2_0, 3_0);

119 @property(nonatomic)        CGSize          titleShadowOffset NS_DEPRECATED_IOS(2_0, 3_0);

120 

121 @end

 

你可能感兴趣的:(UIButton)